Standalone, by setting the origin
and trigger
properties:
<!-- Origin element -->
<div id="autocomplete-origin">Another origin</div>
<!-- Trigger element -->
<input id="autocomplete-txt" placeholder="Another trigger element" />
<sbb-autocomplete origin="autocomplete-origin" trigger="autocomplete-txt">
<sbb-option value="Option A">Option A</sbb-option>
<sbb-option value="Option B">Option B</sbb-option>
<sbb-option value="Option C">Option C</sbb-option>
</sbb-autocomplete>
sbb-option
can be collected into groups using sbb-optgroup
element:
<!-- Origin element -->
<sbb-form-field label="Label">
<!-- Trigger element -->
<input placeholder="Trigger element" />
<sbb-autocomplete>
<sbb-optgroup label="Group 1">
<sbb-option icon-name="clock-small" value="Option 1"> Option 1 </sbb-option>
...
</sbb-optgroup>
<sbb-optgroup label="Group 2">
...
</sbb-optgroup>
</sbb-autocomplete>
</sbb-form-field>
Keyboard shortcut | Action |
---|---|
Down Arrow | Navigate to the next option. Open the panel, if closed. |
Up Arrow | Navigate to the previous option. |
Enter | Select the active option. |
Escape | Close the autocomplete panel. |
sbb-autocomplete
implements the ARIA combobox interaction pattern.
The text input trigger specifies role="combobox"
while the content of the pop-up applies role="listbox"
.
Because of this listbox pattern, you should not put other interactive controls, such as buttons or checkboxes, inside an autocomplete option.
Nesting interactive controls like this interferes with most assistive technology.
sbb-autocomplete
preserves focus on the input trigger, using aria-activedescendant
to support navigation though the autocomplete options.
Property | Attribute | Description | Type | Default |
---|---|---|---|---|
disableAnimation | disable-animation | Whether the animation is disabled. | boolean | false |
origin | origin | The element where the autocomplete will attach; accepts both an element's id or an HTMLElement. If not set, will search for the first 'sbb-form-field' ancestor. | HTMLElement | string | undefined |
preserveIconSpace | preserve-icon-space | Whether the icon space is preserved when no icon is set. | boolean | undefined |
trigger | trigger | The input element that will trigger the autocomplete opening; accepts both an element's id or an HTMLElement. By default, the autocomplete will open on focus, click, input or ArrowDown keypress of the 'trigger' element. If not set, will search for the first 'input' child of a 'sbb-form-field' ancestor. | HTMLInputElement | string | undefined |
Event | Description | Type |
---|---|---|
did-close | Emits whenever the autocomplete is closed. | CustomEvent<void> |
did-open | Emits whenever the autocomplete is opened. | CustomEvent<void> |
will-close | Emits whenever the autocomplete begins the closing transition. | CustomEvent<void> |
will-open | Emits whenever the autocomplete starts the opening transition. | CustomEvent<void> |
close() => Promise<void>
Closes the autocomplete.
Type: Promise<void>
open() => Promise<void>
Opens the autocomplete.
Type: Promise<void>
Slot | Description |
---|---|
"unnamed" | Use this slot to project options. |