SearchField

Component which allows user to enter and clear a search query.

The <SearchField> component offers a user-friendly input field specifically designed for search queries, often accompanied by a search icon or button to initiate the search action.

Anatomy

A <SearchField> consists of an input element, a label, and an optional clear button.

Anatomy of search field

Appearance

The appearance of a component can be customized using the variant and size props. These props adjust the visual style and dimensions of the component, available values are based on the active theme.

Variant
Size
The selected theme does not has any options for "variant" and "size".
PropertyTypeDescription
variant-The available variants of this component.
size-The available sizes of this component.

Usage

The <SearchField> component is a versatile UI element that enables users to search for specific information within a given context or data set.

Placement

The placement of a search field plays a critical role in its effectiveness and usability. A well-positioned search field ensures users can easily find and use it, enhancing their overall experience on a website or application.

Do
Do: Position the search field prominently
Position the search field prominently.
Don't
Don’t place the search field in an obscure location

Don’t place the search field in an obscure location.

Props

Did you know? You can explore, test, and customize props live in Marigold's storybook. Watch the effects they have in real-time!
action?
ReactElement<any, string | JSXElementConstructor<any>>;
Action element to display in the search field.
aria-activedescendant?
string;
Identifies the currently active element when DOM focus is on a composite widget, textbox, group, or application.
aria-autocomplete?
"none" | "inline" | "list" | "both";
Indicates whether inputting text could trigger display of one or more predictions of the user's intended value for an input and specifies how predictions would be presented if they are made.
aria-controls?
string;
Identifies the element (or elements) whose contents or presence are controlled by the current element.
aria-describedby?
string;
Identifies the element (or elements) that describes the object.
aria-details?
string;
Identifies the element (or elements) that provide a detailed, extended description for the object.
aria-errormessage?
string;
Identifies the element that provides an error message for the object.
aria-haspopup?
boolean | "false" | "true" | "menu" | "listbox" | "tree" | "grid" | "dialog";
Indicates the availability and type of interactive popup element, such as menu or dialog, that can be triggered by an element.
aria-label?
string;
Defines a string value that labels the current element.
aria-labelledby?
string;
Identifies the element (or elements) that labels the current element.
autoComplete?
string;
Describes the type of autocomplete functionality the input should provide if any. See MDN.
autoCorrect?
string;
An attribute that takes as its value a space-separated string that describes what, if any, type of autocomplete functionality the input should provide. See MDN.
autoFocus?
boolean;
Whether the element should receive focus on render.
defaultValue?
string;
The default value of the input field.
Defaults to:
"none"
description?
ReactNode;
A helpful text.
disabled?
boolean;
If true, the input is disabled.
Defaults to:
"false"
enterKeyHint?
"enter" | "done" | "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.
error?
boolean;
If true, the input is considered invalid and if set the errorMessage is shown instead of the description.
Defaults to:
"false"
errorMessage?
ReactNode | ((v: ValidationResult) => ReactNode);
An error message.
excludeFromTabOrder?
boolean;
Whether to exclude the element from the sequential tab order. If true, the element will not be focusable via the keyboard by tabbing. This should be avoided except in rare scenarios where an alternative means of accessing the element or its functionality via the keyboard is available.
id?
string;
The element's unique identifier. See MDN.
inputMode?
"search" | "none" | "text" | "url" | "tel" | "email" | "numeric" | "decimal";
Hints at the type of data that might be entered by the user while editing the element or its contents. See MDN.
label?
ReactNode;
Specifies the label of the field.
maxLength?
number;
The maximum number of characters supported by the input. See MDN.
minLength?
number;
The minimum number of characters required by the input. See MDN.
name?
string;
The name of the input element, used when submitting an HTML form. See MDN.
onBeforeInput?
FormEventHandler<HTMLInputElement>;
Handler that is called when the input value is about to be modified. See MDN.
onBlur?
(e: FocusEvent<HTMLInputElement, Element>) => void;
Handler that is called when the element loses focus.
onChange?
(value: string) => void;
Handler that is called when the value changes.
onClear?
() => void;
Handler that is called when the clear button is pressed.
onCompositionEnd?
CompositionEventHandler<HTMLInputElement>;
Handler that is called when a text composition system completes or cancels the current text composition session. See MDN.
onCompositionStart?
CompositionEventHandler<HTMLInputElement>;
Handler that is called when a text composition system starts a new text composition session. See MDN.
onCompositionUpdate?
CompositionEventHandler<HTMLInputElement>;
Handler that is called when a new character is received in the current text composition session. See MDN.
onCopy?
ClipboardEventHandler<HTMLInputElement>;
Handler that is called when the user copies text. See MDN.
onCut?
ClipboardEventHandler<HTMLInputElement>;
Handler that is called when the user cuts text. See MDN.
onFocus?
(e: FocusEvent<HTMLInputElement, Element>) => void;
Handler that is called when the element receives focus.
onFocusChange?
(isFocused: boolean) => void;
Handler that is called when the element's focus status changes.
onInput?
FormEventHandler<HTMLInputElement>;
Handler that is called when the input value is modified. See MDN.
onKeyDown?
(e: KeyboardEvent) => void;
Handler that is called when a key is pressed.
onKeyUp?
(e: KeyboardEvent) => void;
Handler that is called when a key is released.
onPaste?
ClipboardEventHandler<HTMLInputElement>;
Handler that is called when the user pastes text. See MDN.
onSelect?
ReactEventHandler<HTMLInputElement>;
Handler that is called when text in the input is selected. See MDN.
onSubmit?
(value: string) => void;
Handler that is called when the SearchField is submitted.
pattern?
string;
Regex pattern that the value of the input must match to be valid. See MDN.
placeholder?
string;
Placeholder text for the input field.
Defaults to:
"none"
readOnly?
boolean;
If true, the input is readOnly.
Defaults to:
"false"
ref?
Ref<HTMLInputElement>;
Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref). @see {@link https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom React Docs}
required?
boolean;
If true, the input is required.
Defaults to:
"false"
slot?
string | null;
A slot name for the component. Slots allow the component to receive props from a parent component. An explicit null value indicates that the local props completely override all props received from a parent.
spellCheck?
string;
An enumerated attribute that defines whether the element may be checked for spelling errors. See MDN.
type?
"search" | "text" | "url" | "tel" | "email" | "password" | (string & {});
The type of input to render. See MDN.
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 validationBehavior="native". For realtime validation, use the isInvalid prop instead.
validationBehavior?
"native" | "aria";
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.
Defaults to:
'native'
value?
string;
The current value of the input field.
Defaults to:
"none"
width?
WidthProp;
Sets the width of the field. You can see allowed tokens here: https://tailwindcss.com/docs/width
Defaults to:
"full"
Last update: 2 months ago