SearchField
Search allows users to quickly find content. The Search field
is made up of the Text field
component and an optional Button
component.
Basic Usage
Any Paragon component or export may be added to the code example.
With an initial value
Any Paragon component or export may be added to the code example.
With a placeholder
Any Paragon component or export may be added to the code example.
With callbacks
Any Paragon component or export may be added to the code example.
With a custom label
Any Paragon component or export may be added to the code example.
With custom screenreader text
Any Paragon component or export may be added to the code example.
With the submit button outside the input
Any Paragon component or export may be added to the code example.
Advanced Usage
For needs that deviate from the basic usage above, use <SearchField.Advanced />
. The children
elements must contain the SearchField.Label
and SearchField.Input
components at a minimum.
With a custom label
Any Paragon component or export may be added to the code example.
With an initial value
Any Paragon component or export may be added to the code example.
With a placeholder
Any Paragon component or export may be added to the code example.
With no clear button
Any Paragon component or export may be added to the code example.
With no submit or clear buttons
Any Paragon component or export may be added to the code example.
Advanced usage with the submit button outside the input
Use class pgn__searchfield_wrapper
to group input elements apart from the submit button.
Any Paragon component or export may be added to the code example.
Theme Variables#
CSS Variable | Computed Value |
---|---|
| |
| |
| |
| |
| |
Props API#
- onSubmit
func
RequiredSpecifies a callback function for when the
SearchField
is submitted by the user. For example:<SearchField onSubmit={(value) => { console.log(value); } />
- label
string
|element
Specifies the label to use for the input field (e.g., for i18n translations).
- className
string
Specifies a custom class name.
- onBlur
func
Default() => {}Specifies a callback function for when the user loses focus in the
SearchField
component. The default is an empty function. For example:<SearchField onBlur={event => console.log(event)} />
- onChange
func
Default() => {}Specifies a callback function for when the value in
SearchField
is changed by the user. The default is an empty function. For example:<SearchField onChange={value => console.log(value)} />
- onClear
func
Default() => {}Specifies a callback function for when the value in
SearchField
is cleared by the user. The default is an empty function. For example:<SearchField onClear={() => console.log('search cleared')} />
- onFocus
func
Default() => {}Specifies a callback function for when the user focuses in the
SearchField
component. The default is an empty function. For example:<SearchField onFocus={event => console.log(event)} />
- placeholder
string
Specifies the placeholder text for the input.
- screenReaderText
shape
{label:string
|element
Required,submitButton:string
|element
Required,clearButton:}string
|element
,Default{ label: SEARCH_FIELD_SCREEN_READER_TEXT_LABEL, submitButton: SEARCH_FIELD_SCREEN_READER_TEXT_SUBMIT_BUTTON, clearButton: SEARCH_FIELD_SCREEN_READER_TEXT_CLEAR_BUTTON, }Specifies the screenreader text for both the clear and submit buttons (e.g., for i18n translations). The default is
{ label: 'search', clearButton: 'clear search', searchButton: 'submit search' }
. - value
string
Default''Specifies the initial value for the input. The default is an empty string.
- icons
shape
{submit:elementType
Required,clear:}elementType
,Default{ clear: Close, submit: Search, }Specifies the icon element(s) to use for the clear and submit buttons. The default is:
{ submit: import {Search} from '@openedx/paragon/icons';, clear: import {Close} from '@openedx/paragon/icons'. }
- formAriaLabel
string
Specifies the aria-label attribute on the form element. This is useful if you use the
SearchField
component more than once on a page. - inputProps
shape
{}Default{}Props to be passed to the form input
- variant
enum
'light' | 'dark'Default'light'The button style variant to use.
- disabled
bool
DefaultfalseSpecifies whether the
SearchField
is disabled. - submitButtonLocation
enum
'internal' | 'external'Default'internal'Controls whether the search button is internal as an icon or external as a button.
- buttonText
string
Default'search'Specifies a text that is displayed on the button. The
submitButtonLocation
prop should be set toexternal
.
- children
node
Requiredspecifies the nested child elements. At a minimum,
SearchField.Label
andSearchField.Input
are required. - onSubmit
func
Requiredspecifies a callback function for when the
SearchField
is submitted by the user. For example:<SearchField onSubmit={(value) => { console.log(value); } />
- className
string
specifies a custom class name.
- onBlur
func
Default() => {}specifies a callback function for when the user loses focus in the
SearchField
component. The default is an empty function. For example:<SearchField onBlur={event => console.log(event)} />
- onChange
func
Default() => {}specifies a callback function for when the value in
SearchField
is changed by the user. The default is an empty function. For example:<SearchField onChange={value => console.log(value)} />
- onClear
func
Default() => {}specifies a callback function for when the value in
SearchField
is cleared by the user. The default is an empty function. For example:<SearchField onClear={() => console.log('search cleared')} />
- onFocus
func
Default() => {}specifies a callback function for when the user focuses in the
SearchField
component. The default is an empty function. For example:<SearchField onFocus={event => console.log(event)} />
- screenReaderText
shape
{label:string
|element
Required,submitButton:string
|element
Required,clearButton:}string
|element
,Default{ label: 'search', submitButton: 'submit search', clearButton: 'clear search', }specifies the screenreader text for both the clear and submit buttons (e.g., for i18n translations). The default is
{ label: 'search', clearButton: 'clear search', searchButton: 'submit search' }
. - value
string
Default''specifies the initial value for the input. The default is an empty string.
- icons
shape
{submit:elementType
Required,clear:}elementType
,Default{ clear: Close, submit: Search, }specifies the icon element(s) to use for the clear and submit buttons.
- formAriaLabel
string
specifies the aria-label attribute on the form element. This is useful if you use the
SearchField
component more than once on a page. - disabled
bool
DefaultfalseSpecifies whether the
SearchField
is disabled. - submitButtonLocation
enum
'internal' | 'external'Default'internal'Controls whether the search button is internal as an icon or external as a button.
- className
string
specifies a custom class name.
- placeholder
string
specifies the placeholder text for the input.
- children
string
|element
specifies the label to use for the input field (e.g., for i18n translations). Note: if
children
is not provided, a screenreader-only label will be used in its placed based on thescreenReaderText.label
prop forSearchField.Advanced
.
- variant
enum
'light' | 'dark'Default'light'The button style variant to use.
- submitButtonLocation
enum
'internal' | 'external'Default'internal'Controls whether the search button is internal as an icon or external as a button.
- buttonText
string
Default'Search'Specifies a text that is displayed on the button. The
submitButtonLocation
prop should be set toexternal
.
Usage Insights#
SearchField
Project Name | Paragon Version | Instance Count | |
---|---|---|---|
frontend-app-admin-portal | 21.13.1 | 1 | |
frontend-app-course-authoring | 22.8.1 | 1 | |
frontend-app-discussions | 22.7.0 | 1 | |
frontend-app-gradebook | 22.8.1 | 1 | |
frontend-app-library-authoring | 21.11.3 | 1 | |
frontend-app-program-console | 21.13.1 | 1 | |
frontend-app-publisher | 21.13.1 | 1 | |
studio-frontend | 3.4.8 | 1 |
SearchFieldAdvanced
Project Name | Paragon Version | Instance Count | |
---|---|---|---|
frontend-app-discussions | 22.7.0 | 2 | |
frontend-app-learning | 22.10.0 | 1 | |
catalog-search | 21.13.1 | 1 | |
prospectus | 20.46.2 | 5 |
SearchFieldClearButton
Project Name | Paragon Version | Instance Count | |
---|---|---|---|
frontend-app-learning | 22.10.0 | 1 | |
catalog-search | 21.13.1 | 1 | |
prospectus | 20.46.2 | 3 |
SearchFieldInput
Project Name | Paragon Version | Instance Count | |
---|---|---|---|
frontend-app-discussions | 22.7.0 | 2 | |
frontend-app-learning | 22.10.0 | 1 | |
catalog-search | 21.13.1 | 1 | |
prospectus | 20.46.2 | 5 |
SearchFieldLabel
Project Name | Paragon Version | Instance Count | |
---|---|---|---|
frontend-app-discussions | 22.7.0 | 2 | |
frontend-app-learning | 22.10.0 | 1 |
SearchFieldSubmitButton
Project Name | Paragon Version | Instance Count | |
---|---|---|---|
frontend-app-learning | 22.10.0 | 1 | |
catalog-search | 21.13.1 | 1 | |
prospectus | 20.46.2 | 7 |