This page as markdown: /font-picker.md · Index for agents: /llms.txt · Everything in one file: /llms-full.txt

FontPicker

Status: stable

A DisclosurePicker for a typeface: the row names the chosen family in its own face and opens in place into a searchable list of families, each drawn in itself. The app supplies the families and loads the faces; Sable bundles no catalog.

Keywords: font picker, typeface, font family, font selector, typography, google fonts, inspector, customizer

Usage

Use FontPicker wherever someone chooses a typeface for a role (body, headings, code) in a panel that shows the result: a theme editor, a document inspector, a brand customizer. It is a DisclosurePicker, so the list opens beneath the row rather than over the preview; arrow keys walk the families (each drawn in its own face) without applying or loading anything, and Enter, Space or a click picks one, loads it and closes the row.

Best practices

Props

Name Type Default Description
value string — The chosen family, or the value of one of options.
onValueChange (value: string) => void — Called once a family (or option) is picked — Enter, Space or a click — and only when it differs from value; the row then closes. Arrow keys and type-ahead only move focus; Escape closes without a pick.
fonts readonly { family: string; note?: string; stack?: string }[] — The families to offer, in order. note is a muted annotation (searched too); stack the CSS font-family to draw it in (default "<family>").
options readonly { value: string; label: string; valueLabel?: string }[] [] Non-font choices listed above the fonts, in the app's face. valueLabel is what the row shows while it is chosen.
label ReactNode — The row's leading caption — the role the font plays.
listLabel string "Font" Accessible name of the list.
searchable boolean true A search field above the list, filtering by family and note. Pass false for a short curated list (under a dozen).
searchLabel string "Search fonts" Accessible name of the search field.
searchPlaceholder (count: number) => string (count) => Search ${count} fonts The search field's placeholder, given how many fonts are listed.
emptyLabel (query: string) => string (query) => No fonts match “${query}”. What the list says when a search matches nothing.
loadFont (font, purpose: "preview" | "use") => void — Loads a face on demand: "preview" for every family when the list opens, "use" for the chosen one once it is picked (never while the list is only being walked). Receives your own font objects. Idempotent.
open boolean — Controlled open state, as DisclosurePicker. Control it to keep one of several rows open at a time.
defaultOpen boolean false Uncontrolled initial open state.
onOpenChange (open: boolean) => void — Called with the next open state.
size "md" | "sm" | "xs" "md" md for a settings column; sm one rung down for a toolbar; xs for the property-grid rung (see DisclosurePicker).
name / form / required string / string / boolean — Submit the chosen family (or option value) with a form under name, exactly as value holds it, through DisclosurePicker's hidden input — present while the row is closed. required blocks submission while value is empty.

Tokens used

foreground, muted-foreground, popover, hairline, panel-field, ring

Motion

Accessibility

Related

Examples

Body font with lazy loading

import { FontPicker } from "@sableui/react"

const FONTS = [
  { family: "Inter", note: "Neutral, dense UI" },
  { family: "Figtree", note: "Friendly geometric" },
  { family: "Fraunces", note: "Soft, wonky serif", stack: '"Fraunces", serif' },
]
// Your loader; Sable never fetches fonts itself.
const loadFont = (font: { family: string }, purpose: "preview" | "use") => {
  const id = `font-${purpose}-${font.family}`
  if (document.getElementById(id)) return
  const link = Object.assign(document.createElement("link"), { id, rel: "stylesheet" })
  const family = font.family.replace(/ /g, "+")
  link.href = purpose === "preview"
    ? `https://fonts.googleapis.com/css2?family=${family}&text=${encodeURIComponent(font.family)}`
    : `https://fonts.googleapis.com/css2?family=${family}:wght@400..700&display=swap`
  document.head.appendChild(link)
}
const [family, setFamily] = useState("Inter")
<FontPicker label="Body" listLabel="Body font" value={family} onValueChange={setFamily} fonts={FONTS} loadFont={loadFont} searchable={false} />

With a preset option, one row of several

import { FontPicker } from "@sableui/react"

const [open, setOpen] = useState<string | null>(null)
const [body, setBody] = useState("theme")
<FontPicker
  label="Body"
  listLabel="Body font"
  value={body}
  onValueChange={setBody}
  options={[{ value: "theme", label: "Preset (Figtree)", valueLabel: "Figtree" }]}
  fonts={[{ family: "Inter" }, { family: "Figtree" }, { family: "Geist" }]}
  open={open === "body"}
  onOpenChange={(next) => setOpen(next ? "body" : null)}
/>