Class: Primer::Beta::AutoComplete
- Defined in:
- app/components/primer/beta/auto_complete.rb,
app/components/primer/beta/auto_complete/item.rb
Overview
Use AutoComplete to provide a user with a list of selectable suggestions that appear when they type into the input field. This list is populated by server search results.
Defined Under Namespace
Classes: Item
Constant Summary collapse
- DEFAULT_SIZE =
:medium- SIZE_MAPPINGS =
{ :small => "FormControl-small", DEFAULT_SIZE => "FormControl-medium", :large => "FormControl-large" }.freeze
- SIZE_OPTIONS =
SIZE_MAPPINGS.keys
- DEFAULT_WIDTH =
:auto- WIDTH_MAPPINGS =
{ DEFAULT_WIDTH => "Overlay--width-auto", :small => "Overlay--width-small", :medium => "Overlay--width-medium", :large => "Overlay--width-large", :xlarge => "Overlay--width-xlarge", :xxlarge => "Overlay--width-xxlarge" }.freeze
- WIDTH_OPTIONS =
WIDTH_MAPPINGS.keys
Constants inherited from Component
Component::INVALID_ARIA_LABEL_TAGS
Constants included from Status::Dsl
Constants included from ViewHelper
Constants included from TestSelectorHelper
TestSelectorHelper::TEST_SELECTOR_TAG
Constants included from FetchOrFallbackHelper
FetchOrFallbackHelper::InvalidValueError
Constants included from AttributesHelper
AttributesHelper::PLURAL_ARIA_ATTRIBUTES, AttributesHelper::PLURAL_DATA_ATTRIBUTES
Instance Method Summary collapse
-
#before_render ⇒ Object
add
inputandresultswithout needing to explicitly call them in the view. -
#initialize(label_text:, src:, list_id:, input_id:, input_name: nil, placeholder: nil, show_clear_button: false, visually_hide_label: false, size: DEFAULT_SIZE, full_width: false, width: DEFAULT_WIDTH, disabled: false, invalid: false, inset: false, monospace: false, **system_arguments) ⇒ AutoComplete
constructor
A new instance of AutoComplete.
Methods inherited from Component
Methods included from JoinStyleArgumentsHelper
Methods included from TestSelectorHelper
Methods included from FetchOrFallbackHelper
#fetch_or_fallback, #fetch_or_fallback_boolean, #silence_deprecations?
Methods included from ClassNameHelper
Methods included from AttributesHelper
#aria, #data, #merge_aria, #merge_data, #merge_prefixed_attribute_hashes
Constructor Details
#initialize(label_text:, src:, list_id:, input_id:, input_name: nil, placeholder: nil, show_clear_button: false, visually_hide_label: false, size: DEFAULT_SIZE, full_width: false, width: DEFAULT_WIDTH, disabled: false, invalid: false, inset: false, monospace: false, **system_arguments) ⇒ AutoComplete
Returns a new instance of AutoComplete.
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'app/components/primer/beta/auto_complete.rb', line 176 def initialize(label_text:, src:, list_id:, input_id:, input_name: nil, placeholder: nil, show_clear_button: false, visually_hide_label: false, size: DEFAULT_SIZE, full_width: false, width: DEFAULT_WIDTH, disabled: false, invalid: false, inset: false, monospace: false, **system_arguments) @label_text = label_text @list_id = list_id @input_id = input_id @input_name = input_name || input_id @placeholder = placeholder @visually_hide_label = visually_hide_label = @system_arguments = deny_tag_argument(**system_arguments) @system_arguments[:tag] = "auto-complete" @system_arguments[:src] = src @system_arguments[:for] = list_id @disabled = disabled @invalid = invalid @size = size @inset = inset @monospace = monospace @full_width = full_width @width = width @field_wrap_classes = class_names( "FormControl-input-wrap", SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, @size, DEFAULT_SIZE)], "FormControl-input-wrap--trailingAction": ) @form_group_classes = class_names( "FormControl", "FormControl--fullWidth": full_width ) = class_names( "Overlay", "Overlay--height-auto", WIDTH_MAPPINGS[fetch_or_fallback(WIDTH_OPTIONS, @width, DEFAULT_WIDTH)] ) end |
Instance Method Details
#before_render ⇒ Object
add input and results without needing to explicitly call them in the view
212 213 214 215 |
# File 'app/components/primer/beta/auto_complete.rb', line 212 def before_render with_results(classes: "") unless results? with_input(classes: "") unless input? end |