Basic usage
Search is a controlled component. Pass the current query as value and update it from
onValueChange, which receives the next value as a string (an empty string when the field is
cleared).
import {useState} from 'react'
import {Search} from '@pleo-io/telescope'
const EmployeeSearch = () => {
const [query, setQuery] = useState('')
return <Search label="Search employees" value={query} onValueChange={setQuery} />
}The label is rendered as a visually hidden <label>, so screen readers announce what the field
searches. The component is wrapped in a role="search" landmark.
Placeholder
When no placeholder is passed, Search uses the localised default from the TelescopeProvider
translations (Search.Placeholder). Pass placeholder to override it for a specific context.
<Search
label="Search employees"
placeholder="Find a person"
value={query}
onValueChange={setQuery}
/>Other props
Search also accepts the Input props (except variant, prefix, postfix and type) and the
native input props, for example disabled, id and onChange. onChange is still called
alongside onValueChange.
Localisation
The default placeholder is read from the TelescopeProvider translations as Search.Placeholder.
API reference
| Prop | Type | Default |
|---|---|---|
disabledMakes the input disabled if true | boolean | |
innerRefA ref that points to the input | enumRefObject<HTMLInputElement | null> | |
isInvalidA boolean flag that shows the input in an error state if true. | boolean | |
isRequiredAdds aria-required="true" to the input | boolean | |
label (required)Label to be used for VisuallyHidden label | string | '' |
nameThe name of the input | enumstring | undefined | |
onValueChangeCallback called with the string representation of the next value No value will be returned as an empty string | enum(value: string) => void | noop |
renderErrorRender prop for error message | enum() => ReactNode | |
renderInputRender prop for input component. Provides user with access to ariaProps and inputProps, a whitelisted set of props for the input | enum(ariaProps: AriaProps, inputProps: InputHTMLAttributes<HTMLInputElement>) => any | |
skeletonShow a skeleton loading state | boolean | false |
value (required)The current value of the search query | string | '' |