Use Search Input...
- For page search query.
Don't use Search Input...
- If you need our default Search Input with options: use Combobox with Search Input instead.
accessibleTextForClearButton and accessibleTextForClearButton is deprecated in SWAN 3.24. These prop will be removed in favor of SWAN's i18n system. Please opt in to the i18n system and remove these prop.
The preview has been updated.
With floating label
When there are multiple search inputs on a page, the appearance of the search button alone is not sufficient to distinguish between them. In those cases, use a floating label to provide a visible label for the secondary search input on a page. Use the component InputWithFloatingLabel to achieve it.
Note: the floating label has the same appearance as placeholder text but it is not an HTML placeholder; any actual placeholder attribute on the text area is transparent.
The preview has been updated.
Managing state
As is the case with most form elements, folks often want to "control" this component. Controlling a component means that you take ownership over its state rather than letting the browser manage the state for you. When you control a component, you own the source of truth for the UI. This means that you don't need to query the DOM in order to determine the current value of the element. So, when it comes time to use the value of the element somewhere else (e.g. submitting the selection to a back-end service) you can trust your stored value.
To control a SearchInput, store the selected value (e.g., in React state or a Redux store) and provide a handler to update this value when users interact with the component.
The preview has been updated.
If you don't need to manage the state of the SearchInput, you can omit the value and onChange props, allowing the browser to handle the state. Consider using the defaultValue prop to specify the initial selected value and wrapping inside of a StandardForm to handle the onSubmit.
Disabled
Use disabled to prevent users from entering text; when the search action is completely irrelevant to the user's current task and is dependent on a prior selection.
When Search input is part of a Form, use helper text to explain why searching is not possible.
The preview has been updated.
Accessibility
Provide assistive devices with information on what the input field does. You can either:
- Use an
aria-labelattribute with a localized value. - Wrap the Search Input into a
FormFieldwith aFormLabelcomponent with thevisuallyHiddenprop. Refer to Form
Provide assistive devices with information on what the buttons do for the Search and Clear icon buttons that are simply icons and have no visible text. For react users, if you’re not using SWAN’s i18n system, the following props are required: accessibleTextForClearButton and accessibleTextForSearchButton.
Implementation
Avoid placing a Search Input inside an element that is a table cell or has CSS display: table-cell. This configuration may result in the Search Input being rendered more narrowly than its actual minimum width. Use Grid to constrain it instead.