Skip to content
Page

Search Field

Query input with a search icon and a clear button.

Query: —
import { SearchField } from "@pelagornis/page/components";

The preview above renders this file. Copy it into src/components/ to start from it.

src/components/SearchFieldExample.tsx
import { useState } from "react";
import { SearchField, Stack, Text } from "@pelagornis/page/components";
export default function SearchFieldDemo() {
const [query, setQuery] = useState("");
return (
<Stack gap="sizeSmall" className="w-full max-w-sm">
<SearchField value={query} onValueChange={setQuery} aria-label="Search components" />
<SearchField appearance="plain" defaultValue="tokens" aria-label="Plain search" />
<Text variant="captionMd">Query: {query || "—"}</Text>
</Stack>
);
}

Search Field can be written straight in an .mdx page. Import it below the frontmatter. It responds to input, so add client:load to hydrate it.

src/content/docs/example.mdx
---
title: Example
---
import { SearchField } from "@pelagornis/page/components";
<SearchField client:load defaultValue="tokens" aria-label="Search" />

Markdoc tags render Astro components, and this one needs client state. Wrap the example in an .astro file that hydrates it, then register that file as a tag.

src/components/markdoc/SearchFieldExample.astro
---
import SearchFieldExample from "../SearchFieldExample";
---
<SearchFieldExample client:load />
markdoc.config.mjs
import { component, defineMarkdocConfig } from "@astrojs/markdoc/config";
import starlightMarkdoc from "@astrojs/starlight-markdoc";
import pageMarkdoc from "@pelagornis/page/markdoc";
export default defineMarkdocConfig({
extends: [starlightMarkdoc(), pageMarkdoc()],
tags: {
"search-field-example": {
render: component("./src/components/markdoc/SearchFieldExample.astro"),
selfClosing: true,
},
},
});
src/content/docs/example.mdoc
{% search-field-example /%}

Values the component accepts for each variant prop.

PropValues
appearancefilled plain
sizesm md lg

Parts of the component and the data-refineui role each one renders.

PartRole
rootsearch-field
clearsearch-field-clear
iconsearch-field-icon
inputsearch-field-input

States the component styles. Component states are exposed as data attributes.

KindStates
Pseudofocus-visible

Keys the component handles when it has focus.

KeyAction
Escapeclose