Class: Primer::Forms::Dsl::TextFieldInput
- Inherits:
-
Input
- Object
- Input
- Primer::Forms::Dsl::TextFieldInput
show all
- Defined in:
- app/lib/primer/forms/dsl/text_field_input.rb
Overview
Constant Summary
Constants inherited
from Input
Input::DEFAULT_INPUT_WIDTH, Input::DEFAULT_SIZE, Input::INPUT_WIDTH_MAPPINGS, Input::INPUT_WIDTH_OPTIONS, Input::SIZE_MAPPINGS, Input::SIZE_OPTIONS, Input::SPACE_DELIMITED_ARIA_ATTRIBUTES
Instance Attribute Summary
Attributes inherited from Input
#base_id, #builder, #caption, #form, #form_control, #ids, #input_arguments, #label_arguments, #validation_message
Instance Method Summary
collapse
Methods inherited from Input
#add_input_aria, #add_input_classes, #add_input_data, #add_label_classes, #autofocus!, #caption?, #caption_id, #caption_template?, #disabled?, #full_width?, #hidden?, #id, #input?, #input_width, #invalid?, #label, #merge_input_arguments!, #name, #remove_input_data, #render_caption_template, #required?, #size, #supports_validation?, #valid?, #validation_id, #validation_messages, #value, #values_disambiguate_template_names?
#class_names
Constructor Details
#initialize(name:, label:, **system_arguments) ⇒ TextFieldInput
Returns a new instance of TextFieldInput.
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'app/lib/primer/forms/dsl/text_field_input.rb', line 17
def initialize(name:, label:, **system_arguments)
@name = name
@label = label
@show_clear_button = system_arguments.delete(:show_clear_button)
@leading_visual = system_arguments.delete(:leading_visual)
@leading_spinner = !!system_arguments.delete(:leading_spinner)
@clear_button_id = system_arguments.delete(:clear_button_id)
@inset = system_arguments.delete(:inset)
@monospace = system_arguments.delete(:monospace)
@auto_check_src = system_arguments.delete(:auto_check_src)
if @leading_visual
@leading_visual[:classes] = class_names(
"FormControl-input-leadingVisual",
@leading_visual[:classes]
)
end
if @leading_spinner && !@leading_visual
raise ArgumentError, "text fields that request a leading spinner must also specify a leading visual"
end
super(**system_arguments)
add_input_data(:target, "primer-text-field.inputElement #{system_arguments.dig(:data, :target) || ''}")
add_input_classes("FormControl-inset") if inset?
add_input_classes("FormControl-monospace") if monospace?
end
|
Instance Method Details
#focusable? ⇒ Boolean
59
60
61
|
# File 'app/lib/primer/forms/dsl/text_field_input.rb', line 59
def focusable?
true
end
|
#leading_visual? ⇒ Boolean
63
64
65
|
# File 'app/lib/primer/forms/dsl/text_field_input.rb', line 63
def leading_visual?
!!@leading_visual
end
|
#to_component ⇒ Object
51
52
53
|
# File 'app/lib/primer/forms/dsl/text_field_input.rb', line 51
def to_component
TextField.new(input: self)
end
|
#type ⇒ Object
55
56
57
|
# File 'app/lib/primer/forms/dsl/text_field_input.rb', line 55
def type
:text_field
end
|
#validation_arguments ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
|
# File 'app/lib/primer/forms/dsl/text_field_input.rb', line 67
def validation_arguments
if auto_check_src.present?
super.merge(
data: {
target: "primer-text-field.validationElement"
}
)
else
super
end
end
|
#validation_error_icon_target ⇒ Object
83
84
85
|
# File 'app/lib/primer/forms/dsl/text_field_input.rb', line 83
def validation_error_icon_target
"primer-text-field.validationErrorIcon"
end
|
#validation_message_arguments ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
|
# File 'app/lib/primer/forms/dsl/text_field_input.rb', line 87
def validation_message_arguments
if auto_check_src.present?
super.merge(
data: {
target: "primer-text-field.validationMessageElement"
}
)
else
super
end
end
|
#validation_success_icon_target ⇒ Object
79
80
81
|
# File 'app/lib/primer/forms/dsl/text_field_input.rb', line 79
def validation_success_icon_target
"primer-text-field.validationSuccessIcon"
end
|