Skip to content
Page

Select

Pick one value from a list in a popover.

import {
Select,
SelectTrigger,
SelectValue,
SelectContent,
SelectItem,
SelectGroup,
SelectLabel,
SelectSeparator,
} from "@pelagornis/page/components";

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

src/components/SelectExample.tsx
import { useState } from "react";
import {
Select,
SelectContent,
SelectGroup,
SelectItem,
SelectLabel,
SelectSeparator,
SelectTrigger,
SelectValue,
} from "@pelagornis/page/components";
export default function SelectDemo() {
const [framework, setFramework] = useState("astro");
return (
<Select value={framework} onValueChange={setFramework}>
<SelectTrigger aria-label="Framework">
<SelectValue placeholder="Select a framework" />
</SelectTrigger>
<SelectContent>
<SelectGroup>
<SelectLabel>Static</SelectLabel>
<SelectItem value="astro">Astro</SelectItem>
<SelectItem value="eleventy">Eleventy</SelectItem>
</SelectGroup>
<SelectSeparator />
<SelectItem value="next">Next.js</SelectItem>
</SelectContent>
</Select>
);
}

Select is composed from parts that share React state. Children written in MDX are rendered as separate islands, so the parts can’t reach each other. Put the composition in a .tsx file, like the example above, and import that file instead.

src/content/docs/example.mdx
---
title: Example
---
import SelectExample from "../../components/SelectExample";
<SelectExample client:load />

client:load hydrates the island on page load. Use client:visible for content far down the page.

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/SelectExample.astro
---
import SelectExample from "../SelectExample";
---
<SelectExample 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: {
"select-example": {
render: component("./src/components/markdoc/SelectExample.astro"),
selfClosing: true,
},
},
});
src/content/docs/example.mdoc
{% select-example /%}

Values the component accepts for each variant prop.

PropValues
appearancefilled ghost plain

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

PartRole
rootselect-trigger
select_itemselect-item
select_menuselect-menu

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

KindStates
Pseudofocus-visible
data-stateopen closed pressed selected

Keys the component handles when it has focus.

KeyAction
Escapeclose
ArrowDownnext-trigger
ArrowUpprevious-trigger
Homefirst-trigger
Endlast-trigger
Enteractivate
Spaceactivate