Class: Primer::AutoComplete
- Defined in:
- app/components/primer/auto_complete.rb,
app/components/primer/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
Constant Summary
Constants included from Status::Dsl
Constants included from ViewHelper
Constants included from TestSelectorHelper
TestSelectorHelper::TEST_SELECTOR_TAG
Constants included from FetchOrFallbackHelper
FetchOrFallbackHelper::InvalidValueError
Instance Method Summary collapse
-
#before_render ⇒ Object
add ‘results` without needing to explicitly call it in the view.
-
#initialize(src:, list_id:, input_id:, **system_arguments) ⇒ AutoComplete
constructor
A new instance of AutoComplete.
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
Constructor Details
#initialize(src:, list_id:, input_id:, **system_arguments) ⇒ AutoComplete
Returns a new instance of AutoComplete.
105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'app/components/primer/auto_complete.rb', line 105 def initialize(src:, list_id:, input_id:, **system_arguments) @list_id = list_id @input_id = input_id @aria_label = system_arguments[:"aria-label"] || system_arguments.dig(:aria, :label) system_arguments.delete(:"aria-label") && system_arguments[:aria]&.delete(:label) @system_arguments = system_arguments @system_arguments[:tag] = "auto-complete" @system_arguments[:src] = src @system_arguments[:for] = list_id end |
Instance Method Details
#before_render ⇒ Object
add ‘results` without needing to explicitly call it in the view
119 120 121 122 123 124 |
# File 'app/components/primer/auto_complete.rb', line 119 def before_render raise ArgumentError, "Missing `input` slot" if input.blank? raise ArgumentError, "Accessible label is required." if label.blank? && input.missing_label? results(classes: "") unless results end |