Skip to main content

Autocomplete

<gstock-autocomplete> | GstockAutocomplete

API

Properties

Name Description Reflects Type Default
defaultValue The default value of the form control. Primarily used for resetting the form control. string | string[] ''
clearable Adds a clear button when the autocomplete is not empty. boolean false
disabled Disables the autocomplete control. Reflects boolean false
form By default, form controls are associated with the nearest containing <form> element. This attribute allows you to place the form control outside of a form and associate it with the form that has this id. The form must be in the same document or shadow root for this to work. Reflects string ''
filterable Enables filtering of the listbox options. Reflects boolean false
helpText
help-text
The autocomplete’s help text. If you need to display HTML, use the help-text slot instead. string ''
hoist Enable this option to prevent the listbox from being clipped when the component is placed inside a container with `overflow: auto|scroll`. Hoisting uses a fixed positioning strategy that works in many, but not all, scenarios. boolean false
prefix The prefix icon name. string ''
suffix The suffix icon name. string ''
label The autocomplete’s label. If you need to display HTML, use the label slot instead. string ''
maxOptionsVisible
max-options-visible
The maximum number of selected options to show when multiple is true. After the maximum, ”+n” will be shown to indicate the number of additional items that are selected. Set to 0 to remove the limit. number 3
multiple Allows more than one option to be selected. Reflects boolean false
name The name of the autocomplete, submitted as a name/value pair with form data. string ''
open Indicates whether or not the autocomplete is open. You can toggle this attribute to show and hide the menu, or you can use the show() and hide() methods and this attribute will reflect the autocomplete’s open state. Reflects boolean false
placeholder Placeholder text to show as a hint when the autocomplete is empty. string ''
placement The preferred placement of the autocomplete’s menu. Note that the actual placement may vary as needed to keep the listbox inside of the viewport. Reflects 'top' | 'bottom' 'bottom'
required The autocomplete’s required attribute. Reflects boolean false
size The size of the autocomplete. Reflects 'small' | 'medium' | 'large' 'medium'
validityStyles
validity-styles
Specify whether validation styles are applied. false -
value The current value of the autocomplete, submitted as a name/value pair with form data. When multiple is enabled, the value attribute will be a space-delimited list of values based on the options selected, and the value property will be an array. For this reason, values must not contain spaces. string | string[] ''
getChip A function that customizes the chips to be rendered when multiple=true. The first argument is the option, the second is the current chip’s index. The function should return either a Lit TemplateResult or a string containing trusted HTML of the symbol to render at the specified value. function -
validity Gets the validity state object - -
validationMessage Gets the validation message - -
updateComplete

A read-only promise that resolves when the component has finished updating.

Learn more about attributes and properties .

Events

Name React Event Description Event Detail
gstock-change-event onGstockChangeEvent Emitted when the control’s value changes. -
gstock-clear-event onGstockClearEvent Emitted when the control’s value is cleared. -
gstock-input-event onGstockInputEvent Emitted when the control receives input. -
gstock-focus-event onGstockFocusEvent Emitted when the control gains focus. -
gstock-blur-event onGstockBlurEvent Emitted when the control loses focus. -
gstock-show-event onGstockShowEvent Emitted when the autocomplete’s menu opens. -
gstock-after-show-event onGstockAfterShowEvent Emitted after the autocomplete’s menu opens and all animations are complete. -
gstock-hide-event onGstockHideEvent Emitted when the autocomplete’s menu closes. -
gstock-after-hide-event onGstockAfterHideEvent Emitted after the autocomplete’s menu closes and all animations are complete. -
gstock-invalid-event onGstockInvalidEvent Emitted when the form control has been checked for validity and its constraints aren’t satisfied. -

Learn more about events .

Slots

Name Description
default The listbox options. Must be <gstock-option> elements. You can use <gstock-divider> to group items visually.
label The input’s label. Alternatively, you can use the label attribute.
prefix Used to prepend a presentational icon or similar element to the combobox.
clear-icon An icon to use in lieu of the default clear icon.
expand-icon The icon to show when the control is expanded and collapsed. Rotates on open and close.
help-text Text that describes how to use the input. Alternatively, you can use the help-text attribute.
not-found Text that describes when not found results.

Learn more about slots .

Methods

Name Description
show( ) Shows the listbox.
hide( ) Hides the listbox.
checkValidity( ) Checks for validity but does not show a validation message. Returns true when valid and false when invalid.
getForm( ) Gets the associated form, if one exists.
reportValidity( ) Checks for validity and shows the browser’s validation message if the control is invalid.
setCustomValidity(
message: string
)
Sets a custom validation message. Pass an empty string to restore validity.
focus(
options: FocusOptions
)
Sets focus on the control.
blur( ) Removes focus from the control.

Learn more about methods .

CSS Parts

Name Description
form-control The form control that wraps the label, input, and help text.
form-control-label The label’s wrapper.
form-control-input The autocomplete’s wrapper.
form-control-help-text The help text’s wrapper.
combobox The container the wraps the prefix, combobox, clear icon, and expand button.
prefix The container that wraps the prefix slot.
display-input The element that displays the selected option’s label, an <input> element.
listbox The listbox container where options are slotted.
chips The container that houses option chips when multiselect is used.
chip The individual chips that represent each multiselect option.
chip__base The chip’s base part.
chip__content The chip’s content part.
chip__remove-button The chip’s remove button.
chip__remove-button__base The chip’s remove button base part.
clear-button The clear button.
expand-icon The container that wraps the expand icon.

Learn more about CSS parts .

Dependencies

This component automatically imports the following dependencies.