SearchField
Inmatningsfält anpassat för sökning.
import { SearchField } from '@midas-ds/components'
<SearchField placeholder='Sök efter frukter' />
Fältet renderar en sökknapp som standard. Enter-tangenten fungerar alltid för att trigga onSubmit.
Med etikett och beskrivning
Precis som andra fält kan SearchField ta en label och description. Används när fältet inte har en tydlig kontext från omgivningen.
Utan knapp
För realtidsfiltrering eller när ett explicit submit-steg inte behövs kan knappen döljas med showButton={false}. Använd onChange för att reagera på varje tangenttryckning.
Sök med extern knapp
När du behöver mer kontroll över knappens placering eller utseende — komponera en egen Button bredvid fältet.
const [query, setQuery] = React.useState('')
<SearchField
placeholder='Sök efter frukter'
showButton={false}
onChange={setQuery}
/>
<Button onPress={() => handleSubmit(query)}>Sök</Button>
API
| Name | Type | Default | Description |
|---|---|---|---|
placeholder * | string | - | Placeholder text |
label | string | - | Specify label displayed above the SearchField |
description | string | - | Specify description displayed below the label |
popover | InfoPopoverProps | - | |
showButton | boolean | true | Whether to render a built-in submit button. Future flag: pass |
buttonText | string | 'Sök' | Text displayed on the built-in submit button.
@deprecated since v17.9.0 — use your own |
errorMessage | string | - | A custom error message if using the isInvalid prop. |
errorPosition | "bottom" | "top" | top | The position of the error message |
size | Size | large | Component size (large: height 48px, medium: height 40px) |
isDisabled | boolean | - | Whether the input is disabled. |
className | 'react-aria-SearchField' | The CSS className for the element. A function may be provided to compute the class based on component state. | |
type | "email" | "password" | "search" | "tel" | "text" | "url" | (string & {}) | 'search' | The type of input to render. See MDN. |
slot | string | null | - | A slot name for the component. Slots allow the component to receive props from a parent
component. An explicit |
style | StyleOrFunction<SearchFieldRenderProps> | - | The inline style for the element. A function may be provided to compute the style based on component state. |
render | DOMRenderFunction<"div", SearchFieldRenderProps> | - | Overrides the default DOM element with a custom render function. This allows rendering existing components with built-in styles and behaviors such as router links, animation libraries, and pre-styled components. Requirements:
|
defaultValue | string | - | The default value (uncontrolled). |
autoFocus | boolean | - | Whether the element should receive focus on render. |
enterKeyHint | "done" | "enter" | "go" | "next" | "previous" | "search" | "send" | - | An enumerated attribute that defines what action label or icon to preset for the enter key on virtual keyboards. See MDN. |
value | string | - | The current value (controlled). |
isReadOnly | boolean | - | Whether the input can be selected but not changed by the user. |
isInvalid | boolean | - | Whether the input value is invalid. |
validationBehavior | "aria" | "native" | 'native' | Whether to use native HTML form validation to prevent form submission when the value is missing or invalid, or mark the field as required or invalid via ARIA. |
isRequired | boolean | - | Whether user input is required on the input before form submission. |
validate | ((value: string) => true | ValidationError | null) | - | A function that returns an error message if a given value is invalid.
Validation errors are displayed to the user when the form is submitted
if |