Skip to content
weftGitHub

LanguageSelect

Pick a language. Each one also shows its own name, so people can find theirs.

SourcePackage @weft-js/warp

Preview

tsx
import { LanguageSelect } from '@weft-js/warp'export function Basic() {  return (    <LanguageSelect label="Language" preferred={NEAR_LANGUAGES} defaultValue="ja" />  )}const NEAR_LANGUAGES = ['en', 'de', 'ja']

Installation

npm install @weft-js/warp

Usage

tsx
import { LanguageSelect } from '@weft-js/warp'<LanguageSelect label="Language" preferred={NEAR_LANGUAGES} defaultValue="ja" />

Only some languages

options limits the list to the codes you support, regional ones like pt-BR included.

tsx
import { LanguageSelect } from '@weft-js/warp'export function Limited() {  return (    <LanguageSelect label="Docs language" options={['en', 'de', 'ja', 'pt-BR']} defaultValue="pt-BR" hint="We translate the docs into these four." />  )}

Names in another language

locale names the languages in German here. endonyms={false} leaves out each language's own name.

tsx
import { LanguageSelect, Stack } from '@weft-js/warp'export function Locale() {  return (    <Stack gap="group">      <LanguageSelect label="Sprache" locale="de" preferred={NEAR_LANGUAGES} defaultValue="ja" />      <LanguageSelect label="Language" preferred={NEAR_LANGUAGES} defaultValue="ja" endonyms={false} />    </Stack>  )}const NEAR_LANGUAGES = ['en', 'de', 'ja']

States

Read-only also needs open={false}, which keeps the list shut.

tsx
import { Grid, LanguageSelect, Stack, Text } from '@weft-js/warp'export function States() {  return (    <Grid cols={3} gap="group">      <Cell name="Empty"><LanguageSelect label="Language" /></Cell>      <Cell name="Filled"><LanguageSelect label="Language" defaultValue="de" /></Cell>      <Cell name="Hint"><LanguageSelect label="Language" hint="Used in emails and on invoices." /></Cell>      <Cell name="Invalid"><LanguageSelect label="Language" error="Choose a language." /></Cell>      <Cell name="Disabled"><LanguageSelect label="Language" defaultValue="de" disabled /></Cell>      <Cell name="Read-only"><LanguageSelect label="Language" defaultValue="de" readonly /></Cell>    </Grid>  )}const Cell = (p: { name: string; children?: unknown }) => (  <Stack gap="tight">    <Text role="caption" subtle>{p.name}</Text>    {p.children}  </Stack>)

Preview a notification

The value is a language code, ready for lang and your own translations.

tsx
import { state } from '@weft-js/core'import { Card, LanguageSelect, Stack, Text } from '@weft-js/warp'export function Preview() {  const lang = state<string | null>('de')  return (    <Stack gap="group">      <LanguageSelect label="Email language" options={TRANSLATED} value={lang} />      <Card>        <Stack gap="tight">          <Text role="caption" subtle>Preview</Text>          <Text lang={lang.value ?? 'en'}>{HELLO[lang.value ?? 'en']}</Text>        </Stack>      </Card>    </Stack>  )}const HELLO: Record<string, string> = { en: 'Your deploy finished.', de: 'Dein Deploy ist fertig.', ja: 'デプロイが完了しました。', 'pt-BR': 'Seu deploy terminou.' }const TRANSLATED = Object.keys(HELLO)

Accessibility

EnterSpace
Opens the list
↑↓
Moves through the results
Enter
Picks the highlighted row
Esc
Closes and returns focus

API Reference

PropTypeDefaultDescription
labelstring—The visible name, and what screen readers announce.
hintunknown—A short line of help under the field.
errorunknown—Replaces the hint and marks the field invalid.
iconIconRef—Leading icon: it sweeps with the border.
prefixunknown—Text or an element inside the field before the value, such as $.
suffixunknown—Text or an element inside the field after the value, such as kg.
variant"floating" | "classic"—floating (default, or the app's warp({ fields })) · classic: the label above.
appearance"line"—line: only a bottom line under the value, no box or fill. The boxed field otherwise.
size"sm" | "md" | "lg"'md'Control size. md by default.
clearablebooleanfalseA clear button (shown once there is a value).
counternumber—Maximum length, shown as a counter.
idstring—The element id. One is made for you if you leave it out.
disabledbooleanfalseCan't be focused or changed.
readonlybooleanfalseShows the value and lets it be selected and copied, but not changed.
requiredbooleanfalseThe form will not submit without it.
namestring—Posts the value with a form.
localestring—The language names are shown in. Follows the page otherwise.
todaystring—Pins "today" (server render, tests); the browser's clock otherwise.
presentationPresentation—auto opens a popover, or a sheet when the viewport is under 600px wide; popover and sheet force one.
valuestring | State<string | null> | null—The code, or a State to bind.
defaultValuestring | null—The first value, when you don't hold it yourself.
openboolean | State<boolean>—A state box that holds whether it is open.
defaultOpenbooleanfalseStarts open, when the component keeps its own open state.
optionsstring[]—Limits the list to these codes.
preferredstring[]—Codes pinned to the top of the list.
endonymsbooleantrueShows each language's own name beside it.
EventTypeDefaultDescription
onInput((e: InputEvent & { currentTarget: HTMLInputElement & HTMLTextAreaElemen…—Called on each keystroke.
onValueChange((v: string | null, reason: ChangeReason) => void)—Hears the new value and why it changed.
onOpenChange((o: boolean) => void)—Called with true when it opens and false when it closes.

RelatedCountry selectTime zone select