Skip to main content

Search Field

Search Field is a form control that lets people enter a query, such as searching for a member or filtering a catalog.

Import

import { SearchField } from '@vortexlabs/vortex-native';
import type { SearchFieldProps } from '@vortexlabs/vortex-native';

Other links

import { SearchField } from "@vortexlabs/vortex-native";

<SearchField
  name="members"
  label="Search members"
  placeholder="Enter a name"
  size="md"
  variant="fill"
  showLabel={false}
  disabled={false}
  width="100%"
/>

Features

  • Clears an editable query and returns focus to the input.
  • Submits the query from the keyboard’s Search action.
  • Supports responsive sizes and widths.

Sizes

Use size="sm" in a compact toolbar, or pass a breakpoint map to resize the field. The third field grows in height and width at md.

import { SearchField, Stack } from "@vortexlabs/vortex-native";

export const SearchSizes = () => (
  <Stack gap={3} width={280} maxWidth="100%">
    <SearchField size="sm" name="compact" label="Search messages" placeholder="Search messages" />
    <SearchField size="md" name="regular" label="Search messages" placeholder="Search messages" />
    <SearchField
      name="responsive"
      label="Search orders"
      placeholder="Search orders"
      size={{ xs: "sm", md: "md" }}
      width={{ xs: 200, md: 280 }}
    />
  </Stack>
);

Variants

Use variant="outline" for a bordered field. The default is fill.

import { SearchField, Stack } from "@vortexlabs/vortex-native";

export const SearchVariants = () => (
  <Stack gap={3} width={280} maxWidth="100%">
    <SearchField variant="fill" name="fill" label="Search members" defaultValue="Ada" />
    <SearchField variant="outline" name="outline" label="Search members" defaultValue="Ada" />
  </Stack>
);

Label

Set showLabel to keep the field’s purpose visible after someone types a query.

<SearchField
  name="contacts"
  label="Search contacts"
  placeholder="Name or email"
  showLabel
/>

Disabled

Set disabled to prevent editing and hide the clear button.

<SearchField name="disabled" label="Search members" defaultValue="Ada" disabled />

Controlled State

Set value and update it in onChange to own the query. Use onSubmit to run a search when people press the keyboard’s Search action.

import { SearchField, Stack, Text } from "@vortexlabs/vortex-native";
import React from "react";

export const MemberSearch = () => {
	const [query, setQuery] = React.useState("");
	const [submitted, setSubmitted] = React.useState("");

	return (
		<Stack width={280} maxWidth="100%" gap={2}>
			<SearchField
				name="members"
				label="Search members"
				showLabel
				clearLabel="Clear member search"
				placeholder="Enter a name"
				value={query}
				onChange={({ value }) => {
					setQuery(value);
					if (value === "") setSubmitted("");
				}}
				onSubmit={({ value }) => setSubmitted(value.trim())}
			/>
			<Text attributes={{ "aria-live": "polite" }}>
				{submitted ? `Searching for ${submitted}` : "Press Search to submit"}
			</Text>
		</Stack>
	);
};

Use defaultValue to supply an initial query in uncontrolled mode.

Accessibility

Description
label names the input for screen readers even when showLabel is off.
Set clearLabel when the clear action needs a more specific name than “Clear search”.