Zum Inhalt springen
Dokumentation

DokumentationSelect

Select

Eine Auswahl oder viele. Immer der passende Wert.

@rentnerkev/selectDokumentierte Version: v6.2.0

Paket installieren

Verwende React 19 und importiere das Paket-Stylesheet einmal in deinem globalen CSS. Die mitgelieferten Stile sind für Tailwind CSS 4 ausgelegt.

Terminal
bun add @rentnerkev/select
Globales Stylesheet / styles.css
@import '@rentnerkev/select/tailwind.css';

Combobox: mehrere Objekte und asynchrone Ergebnisse#

ComboboxProps<T> unterscheidet den Modus über multiple: true: value ist readonly T[], onValueChange erhält T[]. Der Einzelmodus behält T | null. Steuere searchValue separat und liefere eindeutige stabile getOptionKey-Werte; ausgewählte Objekte bleiben bei neuen asynchronen Ergebnisarrays und Objekten erhalten, auch wenn sie auf der aktuellen Seite fehlen. Die Standardgleichheit vergleicht Schlüssel. filterMode external zeigt deine übergebenen Ergebnisse; Laden, Debounce, Ladezustand, Abbruch und Anlegen übernimmt die Anwendung.

example.tsx
import { Combobox } from '@rentnerkev/select/combobox'
import { useState, type FormEvent } from 'react'

type Customer = { id: string; name: string; email: string }

export default function CustomerTeam({
    results,
    loading = false,
}: {
    results: readonly Customer[]
    loading?: boolean
}) {
    const [selected, setSelected] = useState<readonly Customer[]>([])
    const [query, setQuery] = useState('')
    const [submitted, setSubmitted] = useState<string[]>([])
    function handleSubmit(event: FormEvent<HTMLFormElement>) {
        event.preventDefault()
        setSubmitted(new FormData(event.currentTarget).getAll('customers').map(String))
    }
    return (
        <form onSubmit={handleSubmit}>
            <Combobox
                multiple
                clearable
                name="customers"
                label="Customer team"
                value={selected}
                onValueChange={setSelected}
                searchValue={query}
                onSearchValueChange={setQuery}
                options={results}
                loading={loading}
                filterMode="external"
                getOptionKey={(customer) => customer.id}
                getOptionLabel={(customer) => customer.name}
                getOptionDescription={(customer) => customer.email}
                getFormValue={(customer) => customer.id}
            />
            <button type="submit">Read selected IDs</button>
            <output>{submitted.join(', ')}</output>
        </form>
    )
}

Stabile Erstpositionierung und ShadowRoot-Portale#

CustomSelect und Combobox teilen sich Popupvermessung und Sichtbarkeitsfreigabe. Das aktuelle Popup bleibt verborgen, bis es mit den endgültigen Viewportgrenzen einschließlich Scrollbarbreite vermessen wurde; so blitzt es beim ersten Öffnen nach dem Neuladen nicht an alten Koordinaten auf. Scrollen, Viewportänderungen und ein ausgetauschtes Portal vermessen das Popup neu. ShadowRoot-Portale erhalten Tastaturfokus, feldweites Blur und das Schließen bei Außeninteraktion.

example.tsx
import { CustomSelect } from '@rentnerkev/select'
import { useState } from 'react'

export default function LanguageSelect() {
    const [language, setLanguage] = useState('en')
    return (
        <div className="flex justify-end">
            <CustomSelect
                label="Language"
                contentWidth="content"
                value={language}
                onValueChange={setLanguage}
                options={[
                    { value: 'en', label: 'English' },
                    { value: 'de', label: 'Deutsch' },
                ]}
            />
        </div>
    )
}

Gruppierte Select- und Combobox-Optionen#

Setze option.group am CustomSelect oder liefere einen Gruppennamen über Combobox.getOptionGroup. Gruppenüberschriften sind nicht auswählbar; Einträge ohne Gruppe bleiben verfügbar. Filterung, Tastaturnavigation, deaktivierte Einträge und Virtualisierung funktionieren über Gruppengrenzen hinweg. classNames.group und groupLabel gestalten die Darstellung.

example.tsx
import { useState } from 'react'
import { CustomSelect } from '@rentnerkev/select'
import { Combobox } from '@rentnerkev/select/combobox'

const roles = [
    { id: 'owner', name: 'Owner', group: 'Team' },
    { id: 'editor', name: 'Editor', group: 'Team' },
    { id: 'guest', name: 'Guest', group: 'Visitors' },
]

export default function GroupedChoices() {
    const [role, setRole] = useState('editor')
    const [customer, setCustomer] = useState<(typeof roles)[number] | null>(null)
    const [query, setQuery] = useState('')
    return (
        <section className="grid gap-4">
            <CustomSelect
                label="Role"
                options={roles.map(({ id, name, group }) => ({
                    value: id,
                    label: name,
                    group,
                }))}
                value={role}
                onValueChange={setRole}
            />
            <Combobox
                label="Search roles"
                options={roles}
                value={customer}
                onValueChange={setCustomer}
                searchValue={query}
                onSearchValueChange={setQuery}
                getOptionKey={(option) => option.id}
                getOptionLabel={(option) => option.name}
                getOptionGroup={(option) => option.group}
            />
        </section>
    )
}

Neue Combobox-Option anlegen#

onCreateOption ergänzt eine Zeile zum Anlegen, wenn die getrimmte Suche nicht leer ist und keine vorhandene Option dieselbe Beschriftung hat; Groß- und Kleinschreibung werden ignoriert. createOptionLabel gestaltet den Zeilentext. Der Callback erhält die getrimmte Suche; Erstellen, Speichern und Auswählen übernimmt deine Anwendung. Deaktivierte oder schreibgeschützte Felder können keine Einträge anlegen.

example.tsx
import { useState } from 'react'
import { Combobox } from '@rentnerkev/select/combobox'

type Tag = { id: string; label: string }

export default function CreateTag() {
    const [options, setOptions] = useState<Tag[]>([
        { id: 'react', label: 'React' },
    ])
    const [value, setValue] = useState<Tag | null>(null)
    const [query, setQuery] = useState('')
    function createOption(label: string) {
        const option = { id: crypto.randomUUID(), label }
        setOptions((current) => [...current, option])
        setValue(option)
        setQuery('')
    }
    return (
        <Combobox
            label="Tag"
            options={options}
            value={value}
            onValueChange={setValue}
            searchValue={query}
            onSearchValueChange={setQuery}
            getOptionKey={(option) => option.id}
            getOptionLabel={(option) => option.label}
            onCreateOption={createOption}
            createOptionLabel={(label) => 'Create tag: ' + label}
        />
    )
}

Einzelne ausgewählte Einträge entfernen#

Setze removableSelectedItems an einem mehrfachen CustomSelect, um ausgewählte Beschriftungen ohne Öffnen des Popups zu entfernen. Standardmäßig ist die Option false. Hover oder Tastaturfokus zeigt eine rote Durchstreichung und einen lokalisierten Löschhinweis; Klick, Enter oder Leertaste entfernt nur diesen Wert. Deaktivierte Auswahlen bleiben erhalten. disabled, readOnly und eigenes renderValue unterdrücken die integrierten Löschbuttons.

example.tsx
import { useState } from 'react'
import { CustomSelect } from '@rentnerkev/select'

export default function RemoveSelectedRoles() {
    const [values, setValues] = useState<string[]>(['editor', 'locked'])
    return (
        <CustomSelect
            label="Roles"
            name="roles"
            multiple
            clearable
            removableSelectedItems
            value={values}
            onValueChange={setValues}
            options={[
                { value: 'editor', label: 'Editor' },
                { value: 'reviewer', label: 'Reviewer' },
                { value: 'locked', label: 'Required role', disabled: true },
            ]}
            messages={{
                clickToRemove: 'Click to remove',
                removeSelectedItem: (label) => 'Remove ' + label,
            }}
        />
    )
}

Select 6.0: Migration zum nativen Popup#

Version 6.0.0 ersetzt Radix Select durch ein React-/DOM-Popup. Komponenten-Imports und Props bleiben unverändert. Das Popup ist nichtmodal: Tab und Shift+Tab schließen es und wechseln zu den umgebenden Bedienelementen; Außenklicks schließen es und aktivieren ihr Ziel. Escape und Einzelauswahl setzen den Fokus auf den Auslöser zurück. Optionen einschließlich renderOption-Inhalten werden nur geöffnet gemountet; Typeahead im geschlossenen Zustand verwendet option.label.

example.tsx
import { CustomSelect } from '@rentnerkev/select'
import { useState } from 'react'

export default function NativeSelect() {
    const [value, setValue] = useState('standard')
    return (
        <CustomSelect
            label="Delivery"
            onValueChange={setValue}
            options={[
                { value: 'standard', label: 'Standard' },
                { value: 'express', label: 'Express' },
            ]}
            value={value}
        />
    )
}

Combobox: externe Suchergebnisse#

Neu in 5.2.0: Combobox<T> akzeptiert deine Fachobjekte mit stabilen eindeutigen getOptionKey und getOptionLabel. value und searchValue sind unabhängig: Tippen ändert nur die Suche, Auswählen nur den Wert. Aktualisiere beide im Auswahlhandler, wenn das Label die Suche ersetzen soll. filterMode ist standardmäßig external und zeigt übergebene Ergebnisse unverändert; local aktiviert Label-Filterung. Requests, Debounce und Abbruch übernimmt deine Anwendung. Die Auswahl bleibt bei Seitenwechseln der Ergebnisse bestehen. loading blendet alte Treffer aus; loadingText, emptyText und messages.loading passen Statusmeldungen an.

example.tsx
import { Combobox } from '@rentnerkev/select/combobox'
import { useState } from 'react'

type Customer = { id: string; name: string; email: string }

export default function CustomerSearch({
    results,
    loading = false,
}: {
    results: readonly Customer[]
    loading?: boolean
}) {
    const [customer, setCustomer] = useState<Customer | null>(null)
    const [query, setQuery] = useState('')
    return (
        <Combobox
            clearable
            filterMode="external"
            getOptionDescription={(option) => option.email}
            getOptionKey={(option) => option.id}
            getOptionLabel={(option) => option.name}
            getFormValue={(option) => option.id}
            label="Customer"
            loading={loading}
            name="customerId"
            onSearchValueChange={setQuery}
            onValueChange={(next) => {
                setCustomer(next)
                setQuery(next?.name ?? '')
            }}
            options={results}
            searchValue={query}
            value={customer}
        />
    )
}

Text-Slots, Umbruch & Popupbreite#

Neu in 5.2.0: controlSize sm/md/lg setzt 36/44/48 px; ohne Angabe bleibt die bisherige Größe. textOverflow ist standardmäßig truncate oder wrap für lange Texte. Ein Trigger ohne feste Größe kann bei Umbruch wachsen; eine explizite Größe erhält die Höhe. contentWidth ist standardmäßig trigger oder content, mit der Triggerbreite als Minimum und dem Viewport als Maximum. Text-Slots gestalten optionLabel, optionDescription, optionIndicator, selectedLabel und selectedDescription ohne Nachfahrenselektoren. Slots ersetzen visuelle Vorgaben; verschachtelte Provider erben sie einzeln, ein leerer String entfernt eine Vorgabe. Combobox verwendet search für die Eingabe, ersatzweise trigger.

example.tsx
import { CustomSelect, SelectProvider } from '@rentnerkev/select'
import { useState } from 'react'

export default function Delivery() {
    const [value, setValue] = useState('standard')
    return (
        <SelectProvider
            contentWidth="content"
            portalClassName="font-sans"
            portalZIndex={12000}
            textOverflow="wrap"
            classNames={{
                optionLabel: 'font-semibold',
                selectedLabel: 'text-sky-700',
            }}
        >
            <CustomSelect
                label="Delivery"
                onValueChange={setValue}
                options={[
                    {
                        value: 'standard',
                        label: 'Standard delivery with shipment tracking',
                        subOption: 'Three business days',
                    },
                    {
                        value: 'express',
                        label: 'Express delivery',
                        subOption: 'Next business day',
                    },
                ]}
                value={value}
            />
        </SelectProvider>
    )
}

UI-freier Formularadapter#

getSelectFieldProps aus /form verbindet strukturelle Felder mit CustomSelect oder Combobox ohne React- oder Formularlaufzeit. Es liefert name, value, onValueChange, feldweites onBlur und error. Fehler erscheinen standardmäßig nach Berührung; errorVisibility akzeptiert touched, always oder never. getReadableSelectError akzeptiert Strings oder Objekte mit einer String-message; mapError behandelt andere Formen. Ein null-Fehler überlässt die Validierung ausdrücklich dem Formular. Rufe den Helfer im abonnierten Feld-Render auf; eine Combobox benötigt weiterhin separate searchValue-Handler.

example.tsx
import { CustomSelect } from '@rentnerkev/select'
import {
    getReadableSelectError,
    getSelectFieldProps,
} from '@rentnerkev/select/form'
import type { SelectFormField } from '@rentnerkev/select/form'

export default function RegionField({
    field,
}: {
    field: SelectFormField<string>
}) {
    return (
        <CustomSelect
            {...getSelectFieldProps(field, {
                errorVisibility: 'touched',
                mapError: getReadableSelectError,
            })}
            label="Region"
            options={[{ value: 'eu', label: 'Europe' }]}
        />
    )
}

Gemeinsame Theme-Variablen#

Alle Pakete teilen --rentner-*-CSS-Variablen für control, surface, foreground, muted, border, accent, accent-hover, accent-foreground, danger, success, warning, info und radius. Der Tailwind-Einstieg bindet theme.css automatisch ein; der separate theme.css-Export enthält Variablen, keine vollständigen Komponentenstile. Setze die Variablen für ein globales Theme auf :root. Ein begrenztes Theme muss auch das tatsächliche Portalziel erreichen. customDesign und bisherige Variablen bleiben unterstützt.

styles.css
@import 'tailwindcss';
@import '@rentnerkev/select/tailwind.css';

:root {
    --rentner-control: #ffffff;
    --rentner-surface: #f8fafc;
    --rentner-foreground: #0f172a;
    --rentner-muted: #475569;
    --rentner-border: #64748b;
    --rentner-accent: #0369a1;
    --rentner-accent-hover: #075985;
    --rentner-accent-foreground: #ffffff;
    --rentner-danger: #be123c;
    --rentner-success: #047857;
    --rentner-warning: #b45309;
    --rentner-info: #0369a1;
    --rentner-radius: 0.5rem;
}

Lokale KI-Helfer: Metadaten & Anleitungen#

Importiere den /ai-Einstieg in einem lokalen Node.js- oder Bun-Script. Diese synchronen, nur lesenden Helfer lesen das installierte Paket über node:fs, ohne seine UI zu importieren. getPackageInfo() liefert PackageInfo mit installierter Version, öffentlichen Exports und Peer-Abhängigkeiten. getPackageDocumentation() liefert ein PackageDocument mit path und content; der Standard ist usage, readme wählt README.md. Nur diese beiden mitgelieferten Dokumente sind erlaubt. Die Ergebnisse beschreiben deine installierte Version, die von dieser Website abweichen kann.

inspect-package.ts · Node.js / Bun
import { getPackageDocumentation, getPackageInfo } from '@rentnerkev/select/ai'
import type { PackageDocument, PackageInfo } from '@rentnerkev/select/ai'

const info: PackageInfo = getPackageInfo()
const usage: PackageDocument = getPackageDocumentation()
const readme = getPackageDocumentation('readme')

console.log(info.name, info.version, info.exports, info.peerDependencies)
console.log(usage.path, usage.content)
console.log(readme.path, readme.content)

Lokale KI-Helfer: öffentliche Deklarationen#

getPackageApi() liefert PackageApi mit package, installierter version, gewählten subpaths und declarations als PackageDocument-Objekte. Es liest öffentliche typisierte Einstiege und ihre lokalen Deklarationsabhängigkeiten; /ai selbst ist ausgeschlossen. Mit subpath wie . oder ./types wählst du einen öffentlichen Einstieg. symbol prüft, ob dieser Einstieg den Namen exportiert; die Deklarationsdateien werden nicht auf dieses Symbol gekürzt. Unbekannte Subpfade, ungültige Namen und vom gewählten Einstieg nicht exportierte Namen lösen Fehler aus. Beliebige Dateipfade lassen sich nicht übergeben.

inspect-api.ts · Node.js / Bun
import { getPackageApi } from '@rentnerkev/select/ai'
import type { PackageApi } from '@rentnerkev/select/ai'

const api: PackageApi = getPackageApi()
const selected = getPackageApi({ subpath: '.', symbol: 'CustomSelect' })

console.log(api.package, api.version, api.subpaths)
for (const declaration of selected.declarations) {
    console.log(declaration.path, declaration.content)
}

Lokale KI-Helfer: Suche & Beispiele#

searchPackageDocumentation(query) durchsucht README.md und docs/usage.md mit einem getrimmten, wörtlichen Suchtext ohne Beachtung der Großschreibung. Es liefert PackageSearchMatch-Objekte mit path, einer ab eins gezählten line und passendem text; eine leere Suche liefert ein leeres Array. getPackageExamples() liefert alle eingezäunten Codeblöcke der installierten Anleitung als PackageExample mit language und code. Diese Helfer liefern Text für deine eigenen Tools; sie führen keine Beispiele aus und kontaktieren keinen KI-Dienst.

search-package.ts · Node.js / Bun
import { getPackageExamples, searchPackageDocumentation } from '@rentnerkev/select/ai'
import type { PackageExample, PackageSearchMatch } from '@rentnerkev/select/ai'

const matches: PackageSearchMatch[] = searchPackageDocumentation('CustomSelect')
const examples: PackageExample[] = getPackageExamples()

for (const match of matches) {
    console.log(match.path, match.line, match.text)
}
for (const example of examples) {
    console.log(example.language, example.code)
}

CustomSelect & typisierte Optionen#

Übergib options mit value und label und steuere die Auswahl über value/onValueChange. TValue wird aus deinen Werten abgeleitet und kann String, Zahl oder Objekt sein. subOption ergänzt Hinweise; disabled verhindert die Auswahl einer Option. label, description, placeholder und icon beschreiben das Feld; fallbackOption benennt einen ausgewählten Wert, der in der Optionsliste fehlt.

example.tsx
import { useState } from 'react'
import { CustomSelect } from '@rentnerkev/select'

const options = [
    { value: 'tooltips', label: 'Tooltips', subOption: 'Helpful hints' },
    { value: 'toasts', label: 'Toasts' },
    { value: 'coming-soon', label: 'Coming soon', disabled: true },
]

export default function PackageSelect() {
    const [value, setValue] = useState('')
    return (
        <CustomSelect
            label="Package"
            onValueChange={setValue}
            options={options}
            value={value}
        />
    )
}

Mehrfachauswahl & Grenzen#

Setze multiple und verwende ein Array von Werten. onValueChange liefert ein neues Array. minSelection und maxSelection beschreiben Auswahlgrenzen; maxSelection verhindert zusätzliche Werte oberhalb der Grenze. required und error binden die Prüfung ein. Deaktivierte Optionen können nicht gewählt werden.

example.tsx
import { useState } from 'react'
import { CustomSelect } from '@rentnerkev/select'

const options = ['Tooltips', 'Toasts', 'Inputs'].map((name) => ({
    value: name,
    label: name,
}))

export default function MultiplePackages() {
    const [values, setValues] = useState<string[]>([])
    return (
        <CustomSelect
            label="Packages"
            maxSelection={2}
            minSelection={1}
            multiple
            onValueChange={setValues}
            options={options}
            value={values}
        />
    )
}

Auswahl löschen & emptyValue#

Für eine direkt löschbare Einzelauswahl verwende clearable mit nullable State; Löschen liefert null über onValueChange. emptyValue erlaubt einen eigenen Leerwert, etwa einen leeren String. Der bisherige onClear-Callback bleibt für getrennte Löschlogik verfügbar. Mehrfachauswahl wird auf ein leeres Array zurückgesetzt.

example.tsx
import { useState } from 'react'
import { CustomSelect } from '@rentnerkev/select'

export default function ClearablePackage() {
    const [value, setValue] = useState<string | null>(null)
    return (
        <CustomSelect
            clearable
            label="Package"
            onValueChange={setValue}
            options={[{ value: 'tooltips', label: 'Tooltips' }]}
            value={value}
        />
    )
}

Suche & Tastaturnavigation#

searchable aktiviert das Suchfeld im Popup; false eignet sich für kurze feste Listen. Das Feld unterstützt Tastaturnavigation, Auswahl und Schließen. messages gestaltet Suchnamen, Suchplatzhalter und leere Ergebnisse. Ergänze einen zugänglichen Namen, auch wenn kein sichtbares Label vorhanden ist.

example.tsx
import { useState } from 'react'
import { CustomSelect } from '@rentnerkev/select'

export default function SearchablePackages() {
    const [value, setValue] = useState('')
    return (
        <CustomSelect
            label="Find a package"
            messages={{
                searchPlaceholder: 'Type a package name',
                noResults: 'No matching package',
            }}
            onValueChange={setValue}
            options={[
                { value: 'inputs', label: 'Inputs' },
                { value: 'calendar', label: 'Calendar' },
            ]}
            searchable
            value={value}
        />
    )
}

Objektwerte & Vergleich#

Vergleiche Objektwerte mit isOptionEqualToValue über stabile Schlüssel statt über ihre Identität. So bleibt die Auswahl beim erneuten Laden der Optionen korrekt. getFormValue serialisiert Objektwerte für native Formulare.

example.tsx
import { useState } from 'react'
import { CustomSelect } from '@rentnerkev/select'

type Package = { id: number; name: string }
const options = [{ value: { id: 1, name: 'Tooltips' }, label: 'Tooltips' }]

export default function ObjectSelect() {
    const [value, setValue] = useState<Package | null>(null)
    return (
        <CustomSelect
            clearable
            getFormValue={(item) => String(item.id)}
            isOptionEqualToValue={(option, selected) =>
                option.id === selected.id
            }
            label="Package"
            name="packageId"
            onValueChange={setValue}
            options={options}
            value={value}
        />
    )
}

Eigene Darstellung der Optionen & Werte#

renderOption erhält die Option und ihren selected-/disabled-Zustand. renderValue erhält ein Array der gewählten Optionen, auch im Einzelmodus. Gib React-Inhalt für Badges oder Zusatzinformationen zurück; Tastatur- und Auswahlverhalten bleiben beim Feld.

example.tsx
import { useState } from 'react'
import { CustomSelect } from '@rentnerkev/select'

export default function RichOptions() {
    const [value, setValue] = useState('')
    return (
        <CustomSelect
            label="Package"
            onValueChange={setValue}
            options={[{ value: 'tooltips', label: 'Tooltips' }]}
            renderOption={(option, state) => (
                <span>
                    {state.selected ? '✓ ' : ''}
                    {option.label}
                </span>
            )}
            renderValue={(selected) =>
                selected.map((option) => option.label).join(', ')
            }
            value={value}
        />
    )
}

Native Formulare, Fokus & Feldzustände#

name erzeugt native Formularwerte; getFormValue wandelt eigene Werte in Strings um. Mehrfachfelder senden wiederholte Werte, die FormData.getAll ausliest. omitEmptyFormValue lässt eine leere Mehrfachauswahl weg. id, label, description, error, required und ARIA-Props beschreiben die Prüfung. disabled verhindert Bedienung; readOnly die Bearbeitung. triggerRef fokussiert den Button, onBlur erfasst das Verlassen des Feldes und nonce liefert bei Bedarf einen CSP-Nonce für Komponentenstile.

example.tsx
import { useState } from 'react'
import { CustomSelect } from '@rentnerkev/select'

export default function PackageForm() {
    const [values, setValues] = useState<string[]>([])
    return (
        <form
            onSubmit={(event) => {
                event.preventDefault()
                console.log(
                    new FormData(event.currentTarget).getAll('packages'),
                )
            }}
        >
            <CustomSelect
                label="Packages"
                multiple
                name="packages"
                omitEmptyFormValue
                onValueChange={setValues}
                options={[{ value: 'inputs', label: 'Inputs' }]}
                value={values}
            />
            <button type="submit">Save</button>
        </form>
    )
}

SelectProvider#

Konfiguriere locale, messages, classNames, searchable und nonce für mehrere Selects. Einstellungen am einzelnen Feld überschreiben den nächsten Provider.

example.tsx
import { useState } from 'react'
import { CustomSelect, SelectProvider } from '@rentnerkev/select'

export default function SharedDefaults() {
    const [value, setValue] = useState('')
    return (
        <SelectProvider locale="en" searchable={false}>
            <CustomSelect
                label="Package"
                onValueChange={setValue}
                options={[{ value: 'toasts', label: 'Toasts' }]}
                value={value}
            />
        </SelectProvider>
    )
}

isSingleValueEmpty()#

Der /value-Helfer erkennt einen leeren String, null und undefined als leere Einzelwerte. Er liefert einen booleschen Wert und grenzt den TypeScript-Typ ein.

example.ts
import { isSingleValueEmpty } from '@rentnerkev/select/value'

export const hasSelection = !isSingleValueEmpty('tooltips')
export const isEmpty = isSingleValueEmpty(null)

toggleSelectedValue()#

Schalte einen Wert in einem readonly Auswahlarray mit deiner Vergleichsfunktion um. Vorhandene Werte werden entfernt, neue angehängt. Beim Überschreiten von maxSelection liefert die Funktion null. Das ursprüngliche Array wird nicht verändert.

example.ts
import { toggleSelectedValue } from '@rentnerkev/select/value'

export const next = toggleSelectedValue(
    ['tooltips'],
    'toasts',
    (option, value) => option === value,
    2,
)

Übersetzungen & resolveSelectMessages()#

selectMessageCatalog enthält en, de, es und fr. resolveSelectMessages kombiniert eigene Texte mit der Sprache. Die Texte behandeln Pflicht-/Mindest-/Maximalauswahl, Suche, leere Ergebnisse und Löschen. Die Nachrichten für minSelection und maxSelection sind Funktionen mit der Anzahl als Argument.

example.ts
import { resolveSelectMessages, selectMessageCatalog } from '@rentnerkev/select'

export const messages = resolveSelectMessages('en', {
    noResults: 'No package found',
    maxSelection: (count) => 'Choose up to ' + count + ' packages',
    clearSelection: selectMessageCatalog.en.clearSelection,
})

Klassenbereiche & eigenes Design#

className gestaltet die äußere Komponente. classNames enthält root, trigger, content, search, viewport, option, empty, label, description und clear. Setze nur die Bereiche, die du ändern möchtest, und teile Standardwerte über SelectProvider. Importiere das Tailwind-Stylesheet einmal.

example.tsx
import { useState } from 'react'
import { CustomSelect } from '@rentnerkev/select'
import type { SelectClassNames } from '@rentnerkev/select/types'

const classNames: SelectClassNames = {
    trigger: 'border-2 border-amber-700 bg-amber-50 text-stone-900',
    content: 'bg-amber-50 text-stone-900',
    label: 'font-bold',
}

export default function StyledSelect() {
    const [value, setValue] = useState('')
    return (
        <CustomSelect
            classNames={classNames}
            label="Package"
            onValueChange={setValue}
            options={[{ value: 'calendar', label: 'Calendar' }]}
            value={value}
        />
    )
}

Dokumentation für deine KI-Tools

Verbinde einen kompatiblen MCP-Client, um Paket-APIs, Anleitungen und Beispiele zu lesen. Öffentlich zugänglich, ohne Konto oder API-Schlüssel.

Der entfernte Zugriff ist optional: Trage diese öffentliche URL selbst in deinem MCP-Client ein. Die Verbindung nutzt Streamable HTTP; das Konfigurationsformat kann abweichen. Die lokalen /ai-Helfer lesen die installierte Paketversion in Node.js oder Bun und verbinden sich niemals automatisch mit diesem Server.

MCP / Streamable HTTP
{
    "mcpServers": {
        "rentnerPackages": {
            "url": "https://packages.rentner.dev/mcp"
        }
    }
}

Tools: list_packages, read_package_docs, read_package_api, read_package_examples und search_package_docs.

API & Typen

Veröffentlichte Signaturen, Props und Typen für diese Version. Klappe einen Eintrag auf, um Definition und verfügbare Importpfade zu sehen.

CustomSelectfunction
  • @rentnerkev/select
  • @rentnerkev/select/select
CustomSelect.d.ts
export function CustomSelect<TValue = string>(props: LegacySingleSelectProps<TValue>): ReactElement
export function CustomSelect<TValue = string>(props: DirectClearableSingleSelectProps<TValue>): ReactElement
export function CustomSelect<TValue = string>(props: ConfiguredClearableSingleSelectProps<TValue>): ReactElement
export function CustomSelect<TValue = string>(props: DefaultSingleSelectProps<TValue>): ReactElement
export function CustomSelect<TValue = string>(props: MultipleSelectProps<TValue>): ReactElement
export function CustomSelect<TValue = string>(props: CustomSelectProps<TValue>): ReactElement
export function CustomSelect(props: CustomSelectProps<string>): ReactElement
SelectProviderfunction
  • @rentnerkev/select
SelectProvider.d.ts
export function SelectProvider({ children, ...props }: SelectProviderProps): import("react").JSX.Element
resolveSelectMessagesfunction
  • @rentnerkev/select
  • @rentnerkev/select/messages
resolveSelectMessages.d.ts
export function resolveSelectMessages(locale?: SelectLocale, messages?: Partial<SelectMessages>): SelectMessages
selectMessageCatalogconst
  • @rentnerkev/select
  • @rentnerkev/select/messages
selectMessageCatalog.d.ts
export const selectMessageCatalog: Record<SelectLocale, SelectMessages>
CustomSelectPropstype
  • @rentnerkev/select
  • @rentnerkev/select/types
CustomSelectProps.d.ts
export type CustomSelectProps<TValue = string> = SingleSelectProps<TValue> | MultipleSelectProps<TValue>
MultipleSelectPropstype
  • @rentnerkev/select
  • @rentnerkev/select/types
MultipleSelectProps.d.ts
export type MultipleSelectProps<TValue = string> = SharedCustomSelectProps<TValue> & ClearableSelectProps & {
    value: ReadonlyArray<TValue>
    onValueChange: (value: Array<TValue>) => void
    multiple: true
    /** Enable removal from the built-in closed selection labels. Defaults to false renderValue takes precedence. */
    removableSelectedItems?: boolean
    emptyValue?: never
    omitEmptyFormValue?: boolean
    minSelection?: number
    maxSelection?: number
}

interface SharedCustomSelectProps<TValue> extends AriaAttributes, SelectCustomizationProps {
    id?: string
    name?: string
    options: ReadonlyArray<Option<TValue>>
    required?: boolean
    label?: ReactNode
    description?: ReactNode
    error?: string | null
    disabled?: boolean
    readOnly?: boolean
    triggerRef?: Ref<HTMLButtonElement>
    onBlur?: FocusEventHandler<HTMLDivElement>
    icon?: ReactNode
    placeholder?: string
    className?: string
    classNames?: SelectClassNames
    searchable?: boolean
    nonce?: string
    renderOption?: (option: Option<TValue>, state: SelectOptionState) => ReactNode
    renderValue?: (options: ReadonlyArray<Option<TValue>>) => ReactNode
    fallbackOption?: string
    locale?: SelectLocale
    messages?: Partial<SelectMessages>
    isOptionEqualToValue?: (optionValue: TValue, value: TValue) => boolean
    getFormValue?: (value: TValue) => string
}

type ClearableSelectProps = {
    clearable: true
    onClear?: () => void
} | {
    clearable?: false
    onClear?: never
}
SelectClassNamesinterface
  • @rentnerkev/select
  • @rentnerkev/select/types
SelectClassNames.d.ts
export interface SelectClassNames {
    root?: string
    trigger?: string
    content?: string
    search?: string
    viewport?: string
    option?: string
    group?: string
    groupLabel?: string
    createOption?: string
    empty?: string
    label?: string
    description?: string
    clear?: string
    control?: string
    error?: string
    leading?: string
    trailing?: string
    optionLabel?: string
    optionDescription?: string
    optionIndicator?: string
    selectedLabel?: string
    selectedDescription?: string
    selectedItems?: string
    selectedItem?: string
}
SelectOptionStateinterface
  • @rentnerkev/select
  • @rentnerkev/select/types
SelectOptionState.d.ts
export interface SelectOptionState {
    selected: boolean
    disabled: boolean
}
SingleSelectPropstype
  • @rentnerkev/select
  • @rentnerkev/select/types
SingleSelectProps.d.ts
export type SingleSelectProps<TValue = string> = LegacySingleSelectProps<TValue> | DirectClearableSingleSelectProps<TValue> | ConfiguredClearableSingleSelectProps<TValue> | DefaultSingleSelectProps<TValue>
SelectProviderPropsinterface
  • @rentnerkev/select
  • @rentnerkev/select/types
SelectProviderProps.d.ts
export interface SelectProviderProps extends SelectCustomizationProps {
    children: ReactNode
    locale?: SelectLocale
    messages?: Partial<SelectMessages>
    classNames?: SelectClassNames
    searchable?: boolean
    nonce?: string
}
SelectVirtualizationOptionsinterface
  • @rentnerkev/select
  • @rentnerkev/select/types
SelectVirtualizationOptions.d.ts
export interface SelectVirtualizationOptions {
    estimateSize?: number
    overscan?: number
}
Optioninterface
  • @rentnerkev/select
  • @rentnerkev/select/types
Option.d.ts
export interface Option<TValue = string> {
    value: TValue
    label: string
    subOption?: string
    group?: string
    disabled?: boolean
}
SelectLocaletype
  • @rentnerkev/select
  • @rentnerkev/select/messages
  • @rentnerkev/select/types
SelectLocale.d.ts
export type SelectLocale = 'de' | 'en' | 'es' | 'fr'
SelectMessagesinterface
  • @rentnerkev/select
  • @rentnerkev/select/messages
  • @rentnerkev/select/types
SelectMessages.d.ts
export interface SelectMessages {
    loading?: string
    createOption?: (value: string) => string
    clickToRemove?: string
    removeSelectedItem?: (label: string) => string
    required: string
    minSelection: (count: number) => string
    maxSelection: (count: number) => string
    searchOptions: string
    searchPlaceholder: string
    noResults: string
    noOptions: string
    clearSelection: string
}
Comboboxfunction
  • @rentnerkev/select
  • @rentnerkev/select/combobox
Combobox.d.ts
export function Combobox<T>(props: SingleComboboxProps<T>): ReactElement
export function Combobox<T>(props: MultipleComboboxProps<T>): ReactElement
export function Combobox<T>(props: ComboboxProps<T>): ReactElement
ComboboxPropstype
  • @rentnerkev/select
  • @rentnerkev/select/combobox
  • @rentnerkev/select/combobox/types
ComboboxProps.d.ts
export type ComboboxProps<T> = SingleComboboxProps<T> | MultipleComboboxProps<T>
getSelectFieldPropsfunction
  • @rentnerkev/select
  • @rentnerkev/select/form
getSelectFieldProps.d.ts
export function getSelectFieldProps<T>(field: SelectFormField<T>, options?: SelectFormOptions): SelectFieldProps<T>
getReadableSelectErrorfunction
  • @rentnerkev/select
  • @rentnerkev/select/form
getReadableSelectError.d.ts
export function getReadableSelectError(error: unknown): string | undefined
SelectFormFieldinterface
  • @rentnerkev/select
  • @rentnerkev/select/form
SelectFormField.d.ts
export interface SelectFormField<T> {
    name: string
    state: {
        value: T
        meta?: {
            errors?: ReadonlyArray<unknown>
            isTouched?: boolean
        }
    }
    handleChange: (value: T) => void
    handleBlur: () => void
}
SelectFormOptionsinterface
  • @rentnerkev/select
  • @rentnerkev/select/form
SelectFormOptions.d.ts
export interface SelectFormOptions {
    errorVisibility?: 'touched' | 'always' | 'never'
    mapError?: (error: unknown) => string | undefined
}
SelectFieldPropsinterface
  • @rentnerkev/select
  • @rentnerkev/select/form
SelectFieldProps.d.ts
export interface SelectFieldProps<T> {
    name: string
    value: T
    onValueChange: (value: T) => void
    onBlur: () => void
    error: string | null
}
SelectCustomizationPropsinterface
  • @rentnerkev/select
  • @rentnerkev/select/types
SelectCustomizationProps.d.ts
export interface SelectCustomizationProps {
    /** Auto by default: CustomSelect >= 250 options, Combobox >= 1000 true/options force on, false forces off. */
    virtualized?: boolean | 'auto' | SelectVirtualizationOptions
    controlSize?: 'sm' | 'md' | 'lg'
    textOverflow?: 'truncate' | 'wrap'
    contentWidth?: 'trigger' | 'content'
    portalContainer?: Element | DocumentFragment | null
    portalClassName?: string
    portalZIndex?: number
}
isSingleValueEmptyfunction
  • @rentnerkev/select/value
isSingleValueEmpty.d.ts
export function isSingleValueEmpty(value: unknown): value is '' | null | undefined
toggleSelectedValuefunction
  • @rentnerkev/select/value
toggleSelectedValue.d.ts
export function toggleSelectedValue<TValue>(selectedValues: ReadonlyArray<TValue>, nextValue: TValue, isEqual: SelectValueComparator<TValue>, maxSelection?: number): Array<TValue> | null
SelectValueComparatortype
  • @rentnerkev/select/value
SelectValueComparator.d.ts
export type SelectValueComparator<TValue> = (optionValue: TValue, value: TValue) => boolean
SelectVirtualNavigationinterface
  • @rentnerkev/select/types
SelectVirtualNavigation.d.ts
export interface SelectVirtualNavigation {
    handleKeyDown: (event: KeyboardEvent<HTMLDivElement>) => boolean
    handleContentFocus: () => void
}
LegacySingleSelectPropstype
  • @rentnerkev/select/types
LegacySingleSelectProps.d.ts
export type LegacySingleSelectProps<TValue = string> = SingleSelectPropsBase<TValue> & {
    clearable: true
    onClear: () => void
    emptyValue?: never
    onValueChange: (value: TValue) => void
}

type SingleSelectPropsBase<TValue> = SharedCustomSelectProps<TValue> & {
    value: TValue | null | undefined
    multiple?: false
    removableSelectedItems?: never
}

interface SharedCustomSelectProps<TValue> extends AriaAttributes, SelectCustomizationProps {
    id?: string
    name?: string
    options: ReadonlyArray<Option<TValue>>
    required?: boolean
    label?: ReactNode
    description?: ReactNode
    error?: string | null
    disabled?: boolean
    readOnly?: boolean
    triggerRef?: Ref<HTMLButtonElement>
    onBlur?: FocusEventHandler<HTMLDivElement>
    icon?: ReactNode
    placeholder?: string
    className?: string
    classNames?: SelectClassNames
    searchable?: boolean
    nonce?: string
    renderOption?: (option: Option<TValue>, state: SelectOptionState) => ReactNode
    renderValue?: (options: ReadonlyArray<Option<TValue>>) => ReactNode
    fallbackOption?: string
    locale?: SelectLocale
    messages?: Partial<SelectMessages>
    isOptionEqualToValue?: (optionValue: TValue, value: TValue) => boolean
    getFormValue?: (value: TValue) => string
}
DirectClearableSingleSelectPropstype
  • @rentnerkev/select/types
DirectClearableSingleSelectProps.d.ts
export type DirectClearableSingleSelectProps<TValue = string> = SingleSelectPropsBase<TValue> & {
    clearable: true
    onClear?: never
    emptyValue?: null
    onValueChange: (value: TValue | null) => void
}

type SingleSelectPropsBase<TValue> = SharedCustomSelectProps<TValue> & {
    value: TValue | null | undefined
    multiple?: false
    removableSelectedItems?: never
}

interface SharedCustomSelectProps<TValue> extends AriaAttributes, SelectCustomizationProps {
    id?: string
    name?: string
    options: ReadonlyArray<Option<TValue>>
    required?: boolean
    label?: ReactNode
    description?: ReactNode
    error?: string | null
    disabled?: boolean
    readOnly?: boolean
    triggerRef?: Ref<HTMLButtonElement>
    onBlur?: FocusEventHandler<HTMLDivElement>
    icon?: ReactNode
    placeholder?: string
    className?: string
    classNames?: SelectClassNames
    searchable?: boolean
    nonce?: string
    renderOption?: (option: Option<TValue>, state: SelectOptionState) => ReactNode
    renderValue?: (options: ReadonlyArray<Option<TValue>>) => ReactNode
    fallbackOption?: string
    locale?: SelectLocale
    messages?: Partial<SelectMessages>
    isOptionEqualToValue?: (optionValue: TValue, value: TValue) => boolean
    getFormValue?: (value: TValue) => string
}
ConfiguredClearableSingleSelectPropstype
  • @rentnerkev/select/types
ConfiguredClearableSingleSelectProps.d.ts
export type ConfiguredClearableSingleSelectProps<TValue = string> = SingleSelectPropsBase<TValue> & {
    clearable: true
    onClear?: never
    emptyValue: TValue
    onValueChange: (value: TValue) => void
}

type SingleSelectPropsBase<TValue> = SharedCustomSelectProps<TValue> & {
    value: TValue | null | undefined
    multiple?: false
    removableSelectedItems?: never
}

interface SharedCustomSelectProps<TValue> extends AriaAttributes, SelectCustomizationProps {
    id?: string
    name?: string
    options: ReadonlyArray<Option<TValue>>
    required?: boolean
    label?: ReactNode
    description?: ReactNode
    error?: string | null
    disabled?: boolean
    readOnly?: boolean
    triggerRef?: Ref<HTMLButtonElement>
    onBlur?: FocusEventHandler<HTMLDivElement>
    icon?: ReactNode
    placeholder?: string
    className?: string
    classNames?: SelectClassNames
    searchable?: boolean
    nonce?: string
    renderOption?: (option: Option<TValue>, state: SelectOptionState) => ReactNode
    renderValue?: (options: ReadonlyArray<Option<TValue>>) => ReactNode
    fallbackOption?: string
    locale?: SelectLocale
    messages?: Partial<SelectMessages>
    isOptionEqualToValue?: (optionValue: TValue, value: TValue) => boolean
    getFormValue?: (value: TValue) => string
}
DefaultSingleSelectPropstype
  • @rentnerkev/select/types
DefaultSingleSelectProps.d.ts
export type DefaultSingleSelectProps<TValue = string> = SingleSelectPropsBase<TValue> & {
    clearable?: false
    onClear?: never
    emptyValue?: never
    onValueChange: (value: TValue) => void
}

type SingleSelectPropsBase<TValue> = SharedCustomSelectProps<TValue> & {
    value: TValue | null | undefined
    multiple?: false
    removableSelectedItems?: never
}

interface SharedCustomSelectProps<TValue> extends AriaAttributes, SelectCustomizationProps {
    id?: string
    name?: string
    options: ReadonlyArray<Option<TValue>>
    required?: boolean
    label?: ReactNode
    description?: ReactNode
    error?: string | null
    disabled?: boolean
    readOnly?: boolean
    triggerRef?: Ref<HTMLButtonElement>
    onBlur?: FocusEventHandler<HTMLDivElement>
    icon?: ReactNode
    placeholder?: string
    className?: string
    classNames?: SelectClassNames
    searchable?: boolean
    nonce?: string
    renderOption?: (option: Option<TValue>, state: SelectOptionState) => ReactNode
    renderValue?: (options: ReadonlyArray<Option<TValue>>) => ReactNode
    fallbackOption?: string
    locale?: SelectLocale
    messages?: Partial<SelectMessages>
    isOptionEqualToValue?: (optionValue: TValue, value: TValue) => boolean
    getFormValue?: (value: TValue) => string
}
SelectDefaultstype
  • @rentnerkev/select/types
SelectDefaults.d.ts
export type SelectDefaults = Omit<SelectProviderProps, 'children'>
SelectOptionHandlersinterface
  • @rentnerkev/select/types
SelectOptionHandlers.d.ts
export interface SelectOptionHandlers<TValue> {
    handleOptionPointerDown: (event?: PointerEvent<HTMLDivElement>) => void
    handleOptionPointerUp?: (event: PointerEvent<HTMLDivElement>, value: string) => void
    handleOptionPointerMove?: (event: PointerEvent<HTMLDivElement>) => void
    handleOptionClick?: (event: MouseEvent<HTMLDivElement>, value: string) => void
    handleOptionFocus: (value: TValue, event?: FocusEvent<HTMLDivElement>) => void
    handleOptionBlur: (event: FocusEvent<HTMLDivElement>) => void
    handleOptionKeyDown: (event: KeyboardEvent<HTMLDivElement>) => void
}
SelectOptionsPropsinterface
  • @rentnerkev/select/types
SelectOptionsProps.d.ts
export interface SelectOptionsProps<TValue> {
    entries: ReadonlyArray<OptionEntry<TValue>>
    multiple: boolean
    renderOption: SharedCustomSelectProps<TValue>['renderOption']
    className: string | undefined
    classNames: SelectClassNames
    textOverflow: 'truncate' | 'wrap'
    isSelected: (value: TValue) => boolean
    isOptionDisabled: (option: Option<TValue>) => boolean
    handler: SelectOptionHandlers<TValue>
}

interface SharedCustomSelectProps<TValue> extends AriaAttributes, SelectCustomizationProps {
    id?: string
    name?: string
    options: ReadonlyArray<Option<TValue>>
    required?: boolean
    label?: ReactNode
    description?: ReactNode
    error?: string | null
    disabled?: boolean
    readOnly?: boolean
    triggerRef?: Ref<HTMLButtonElement>
    onBlur?: FocusEventHandler<HTMLDivElement>
    icon?: ReactNode
    placeholder?: string
    className?: string
    classNames?: SelectClassNames
    searchable?: boolean
    nonce?: string
    renderOption?: (option: Option<TValue>, state: SelectOptionState) => ReactNode
    renderValue?: (options: ReadonlyArray<Option<TValue>>) => ReactNode
    fallbackOption?: string
    locale?: SelectLocale
    messages?: Partial<SelectMessages>
    isOptionEqualToValue?: (optionValue: TValue, value: TValue) => boolean
    getFormValue?: (value: TValue) => string
}
CustomSelectLogicResultinterface
  • @rentnerkev/select/types
CustomSelectLogicResult.d.ts
export interface CustomSelectLogicResult<TValue> {
    state: SelectCustomizationProps & {
        popupStyle: CSSProperties
        popupId: string
        portalTarget: Element | DocumentFragment | null
        virtualOptionsModule: typeof import('../Components/VirtualSelectOptions.tsx') | null
        virtualized: boolean | SelectVirtualizationOptions
        textOverflow: 'truncate' | 'wrap'
        contentWidth: 'trigger' | 'content'
        name: string | undefined
        required: boolean
        disabled: boolean
        readOnly: boolean
        externalError: string | null | undefined
        label: ReactNode
        description: ReactNode
        icon: ReactNode
        placeholder: string | undefined
        className: string | undefined
        classNames: SelectClassNames
        searchable: boolean
        nonce: string | undefined
        renderOption: SharedCustomSelectProps<TValue>['renderOption']
        renderValue: SharedCustomSelectProps<TValue>['renderValue']
        fallbackOption: string | undefined
        multiple: boolean
        omitEmptyFormValue: boolean
        clearable: boolean
        selectedValues: ReadonlyArray<TValue>
        formEntries: ReadonlyArray<{
            key: string
            value: string
        }>
        ariaProps: AriaAttributes
        ariaLabel: string | undefined
        describedBy: string | undefined
        labelledBy: string | undefined
        showClear: boolean
        showRemovableSelectedItems?: boolean
        isOptionDisabled: (option: Option<TValue>) => boolean
        selectedOptions: ReadonlyArray<Option<TValue>>
        selectedLabel: string
        messages: SelectMessages
        triggerId: string
        labelId: string
        descriptionId: string
        errorId: string
        open: boolean
        searchValue: string
        optionEntries: ReadonlyArray<OptionEntry<TValue>>
        filteredOptions: ReadonlyArray<OptionEntry<TValue>>
        selectedEntries: ReadonlyArray<OptionEntry<TValue>>
        selectedRadixValue: string
        hasError: boolean
        resolvedError: string | null
        hasLeftIcon: boolean
        isOptionEqualToValue: (optionValue: TValue, value: TValue) => boolean
        isValueSelected: (value: TValue) => boolean
    }
    handler: {
        option: SelectOptionHandlers<TValue>
        handleVirtualClose: () => void
        handleContentFocusCapture: (event: FocusEvent<HTMLDivElement>) => void
        handleTriggerPointerDown: (event: PointerEvent<HTMLButtonElement>) => void
        handleTriggerClick: () => void
        handleTriggerKeyDown: (event: KeyboardEvent<HTMLButtonElement>) => void
        handleSearchChange: (event: ChangeEvent<HTMLInputElement>) => void
        handleSearchPointerDown: (event: PointerEvent<HTMLInputElement>) => void
        handleSearchKeyDown: (event: KeyboardEvent<HTMLInputElement>) => void
        handleFieldBlur: (event: FocusEvent<HTMLDivElement>) => void
        handleInvalid: (event: InvalidEvent<HTMLInputElement>) => void
        handleValueChange: (value: string) => void
        handleClear: () => void
        handleRemoveSelectedItem?: (optionKey: string) => void
        handleOpenChange: (open: boolean) => void
        closeAfterOptionRemoval: () => void
        handleContentKeyDownCapture: (event: KeyboardEvent<HTMLDivElement>) => void
    }
    refs: {
        root: RefObject<HTMLDivElement | null>
        content: RefObject<HTMLDivElement | null>
        overlayContent: RefCallback<HTMLDivElement>
        trigger: RefCallback<HTMLButtonElement>
        searchInput: RefObject<HTMLInputElement | null>
        validationInput: RefObject<HTMLInputElement | null>
        scroll: RefObject<HTMLDivElement | null>
        virtualNavigation: RefObject<SelectVirtualNavigation | null>
        pendingVirtualNavigation: RefObject<Array<KeyboardEvent<HTMLDivElement>>>
    }
}

interface SharedCustomSelectProps<TValue> extends AriaAttributes, SelectCustomizationProps {
    id?: string
    name?: string
    options: ReadonlyArray<Option<TValue>>
    required?: boolean
    label?: ReactNode
    description?: ReactNode
    error?: string | null
    disabled?: boolean
    readOnly?: boolean
    triggerRef?: Ref<HTMLButtonElement>
    onBlur?: FocusEventHandler<HTMLDivElement>
    icon?: ReactNode
    placeholder?: string
    className?: string
    classNames?: SelectClassNames
    searchable?: boolean
    nonce?: string
    renderOption?: (option: Option<TValue>, state: SelectOptionState) => ReactNode
    renderValue?: (options: ReadonlyArray<Option<TValue>>) => ReactNode
    fallbackOption?: string
    locale?: SelectLocale
    messages?: Partial<SelectMessages>
    isOptionEqualToValue?: (optionValue: TValue, value: TValue) => boolean
    getFormValue?: (value: TValue) => string
}
InternalCustomSelectLogicResulttype
  • @rentnerkev/select/types
InternalCustomSelectLogicResult.d.ts
export type InternalCustomSelectLogicResult<TValue> = CustomSelectLogicResult<TValue> & {
    handler: {
        handleRemoveSelectedItem: (optionKey: string) => void
    }
}
SelectProviderLogicResultinterface
  • @rentnerkev/select/types
SelectProviderLogicResult.d.ts
export interface SelectProviderLogicResult {
    state: {
        contextValue: SelectDefaults
    }
}
SelectValueOptionstype
  • @rentnerkev/select/types
SelectValueOptions.d.ts
export type SelectValueOptions<TValue> = Pick<SingleSelectProps<TValue>, SelectValueKeys> | Pick<MultipleSelectProps<TValue>, SelectValueKeys | 'maxSelection'>

type SelectValueKeys = 'value' | 'onValueChange' | 'multiple' | 'options' | 'emptyValue' | 'onClear' | 'getFormValue' | 'isOptionEqualToValue'
SelectValuesResultinterface
  • @rentnerkev/select/types
SelectValuesResult.d.ts
export interface SelectValuesResult<TValue> {
    state: {
        selectedValues: ReadonlyArray<TValue>
        formEntries: ReadonlyArray<{
            key: string
            value: string
        }>
    }
    handler: {
        handleSelectValue: (value: TValue) => void
        handleClearValues: () => void
    }
}
SelectOptionIdentityResultinterface
  • @rentnerkev/select/types
SelectOptionIdentityResult.d.ts
export interface SelectOptionIdentityResult<TValue> {
    state: {
        optionEntries: ReadonlyArray<OptionEntry<TValue>>
    }
}
PackageInfointerface
  • @rentnerkev/select/ai
PackageInfo.d.ts
export interface PackageInfo {
    name: string
    version: string
    description: string
    license: string
    homepage: string
    repository: {
        type: string
        url: string
    }
    exports: Record<string, string | {
        types?: string
        import?: string
        default?: string
    }>
    peerDependencies: Record<string, string>
}
PackageDocumentinterface
  • @rentnerkev/select/ai
PackageDocument.d.ts
export interface PackageDocument {
    path: string
    content: string
}
PackageApiinterface
  • @rentnerkev/select/ai
PackageApi.d.ts
export interface PackageApi {
    package: string
    version: string
    subpaths: Record<string, string>
    declarations: PackageDocument[]
}
PackageSearchMatchinterface
  • @rentnerkev/select/ai
PackageSearchMatch.d.ts
export interface PackageSearchMatch {
    path: string
    line: number
    text: string
}
PackageExampleinterface
  • @rentnerkev/select/ai
PackageExample.d.ts
export interface PackageExample {
    language: string
    code: string
}
getPackageInfofunction
  • @rentnerkev/select/ai
getPackageInfo.d.ts
export function getPackageInfo(): PackageInfo
getPackageDocumentationfunction
  • @rentnerkev/select/ai
getPackageDocumentation.d.ts
export function getPackageDocumentation(document?: 'readme' | 'usage'): PackageDocument
getPackageApifunction
  • @rentnerkev/select/ai
getPackageApi.d.ts
export function getPackageApi(options?: {
    subpath?: string
    symbol?: string
}): PackageApi
searchPackageDocumentationfunction
  • @rentnerkev/select/ai
searchPackageDocumentation.d.ts
export function searchPackageDocumentation(query: string): PackageSearchMatch[]
getPackageExamplesfunction
  • @rentnerkev/select/ai
getPackageExamples.d.ts
export function getPackageExamples(): PackageExample[]
ComboboxBasePropsinterface
  • @rentnerkev/select/combobox/types
ComboboxBaseProps.d.ts
export interface ComboboxBaseProps<T> extends AriaAttributes, SelectCustomizationProps {
    options: ReadonlyArray<T>
    searchValue: string
    onSearchValueChange: (value: string) => void
    getOptionKey: (option: T) => string
    getOptionLabel: (option: T) => string
    getOptionGroup?: (option: T) => string | undefined
    /** Receives a trimmed query the application owns creating and selecting the new option. */
    onCreateOption?: (searchValue: string) => void
    createOptionLabel?: (searchValue: string) => string
    getOptionDescription?: (option: T) => ReactNode
    isOptionDisabled?: (option: T) => boolean
    isOptionEqualToValue?: (option: T, value: T) => boolean
    renderOption?: (option: T, state: {
        selected: boolean
        active: boolean
        disabled: boolean
    }) => ReactNode
    filterMode?: 'external' | 'local'
    loading?: boolean
    loadingText?: ReactNode
    emptyText?: ReactNode
    clearable?: boolean
    id?: string
    name?: string
    getFormValue?: (value: T) => string
    label?: ReactNode
    description?: ReactNode
    error?: string | null
    required?: boolean
    disabled?: boolean
    readOnly?: boolean
    placeholder?: string
    inputRef?: Ref<HTMLInputElement>
    onBlur?: (event: FocusEvent<HTMLDivElement>) => void
    className?: string
    classNames?: SelectClassNames
    locale?: SelectLocale
    messages?: Partial<SelectMessages>
}
SingleComboboxPropsinterface
  • @rentnerkev/select/combobox/types
SingleComboboxProps.d.ts
export interface SingleComboboxProps<T> extends ComboboxBaseProps<T> {
    multiple?: false
    value: T | null
    onValueChange: (value: T | null) => void
}
MultipleComboboxPropsinterface
  • @rentnerkev/select/combobox/types
MultipleComboboxProps.d.ts
export interface MultipleComboboxProps<T> extends ComboboxBaseProps<T> {
    multiple: true
    value: ReadonlyArray<T>
    onValueChange: (value: T[]) => void
}
ComboboxEntryinterface
  • @rentnerkev/select/combobox/types
ComboboxEntry.d.ts
export interface ComboboxEntry<T> {
    option: T
    key: string
    id: string
    label: string
    group?: string
    position?: number
    description: ReactNode
    disabled: boolean
    selected: boolean
}
ComboboxLogicResultinterface
  • @rentnerkev/select/combobox/types
ComboboxLogicResult.d.ts
export interface ComboboxLogicResult<T> {
    state: {
        virtualOptionsModule: typeof import('../Components/VirtualComboboxOptions.tsx') | null
        inputId: string
        listId: string
        hasLabel: boolean
        labelId: string
        descriptionId: string
        errorId: string
        labelledBy: string | undefined
        describedBy: string | undefined
        open: boolean
        activeId: string | undefined
        activeEntry: ComboboxEntry<T> | undefined
        activeIndex: number
        navigationVersion: number
        virtualization: boolean | SelectVirtualizationOptions
        entries: ReadonlyArray<ComboboxEntry<T>>
        messages: SelectMessages
        classNames: SelectClassNames
        controlSize: SelectCustomizationProps['controlSize']
        textOverflow: 'truncate' | 'wrap'
        portalContainer: Element | DocumentFragment | null | undefined
        portalClassName: string | undefined
        popupStyle: CSSProperties
        multiple: boolean
        selectedItems: ReadonlyArray<{
            key: string
            label: string
            disabled: boolean
            removeLabel: string
        }>
        formValues: ReadonlyArray<{
            key: string
            value: string
        }>
        emptySelection: boolean
        formValue: string
        hasError: boolean
        error: string | null | undefined
        loadingText: ReactNode
        emptyText: ReactNode
        showClear: boolean
        canCreate?: boolean
        createLabel?: string
        createId?: string
        createActive?: boolean
    }
    handler: {
        handleChange: (event: ChangeEvent<HTMLInputElement>) => void
        handleFocus: () => void
        handleKeyDown: (event: KeyboardEvent<HTMLInputElement>) => void
        handleFieldBlur: (event: FocusEvent<HTMLDivElement>) => void
        handleOptionSelect: (entry: ComboboxEntry<T>) => void
        handleOptionActivate: (key: string) => void
        handleKeepFocus: (event: MouseEvent<HTMLElement>) => void
        handleClear: () => void
        handleRemoveSelectedItem: (key: string) => void
        handleInvalid: (event: InvalidEvent<HTMLInputElement>) => void
        handleCreateOption?: () => void
        handleCreateActivate?: () => void
    }
    refs: {
        root: RefObject<HTMLDivElement | null>
        content: RefObject<HTMLDivElement | null>
        popupContent: RefCallback<HTMLDivElement>
        validation: RefObject<HTMLInputElement | null>
        input: RefCallback<HTMLInputElement>
    }
}
InternalComboboxLogicResulttype
  • @rentnerkev/select/combobox/types
InternalComboboxLogicResult.d.ts
export type InternalComboboxLogicResult<T> = ComboboxLogicResult<T> & {
    state: {
        entries: ReadonlyArray<ComboboxEntry<T> & {
            position: number
        }>
    }
}
ComboboxOptionPropsinterface
  • @rentnerkev/select/combobox/types
ComboboxOptionProps.d.ts
export interface ComboboxOptionProps<T> {
    entry: ComboboxEntry<T>
    state: Pick<ComboboxLogicResult<T>['state'], 'activeId' | 'classNames' | 'textOverflow'>
    handler: Pick<ComboboxLogicResult<T>['handler'], 'handleKeepFocus' | 'handleOptionActivate' | 'handleOptionSelect'>
    renderOption: ComboboxProps<T>['renderOption']
    index?: number
    setSize?: number
    measureElement?: RefCallback<HTMLDivElement>
    style?: CSSProperties
}
VirtualComboboxOptionsPropsinterface
  • @rentnerkev/select/combobox/types
VirtualComboboxOptionsProps.d.ts
export interface VirtualComboboxOptionsProps<T> {
    state: Pick<ComboboxLogicResult<T>['state'], 'multiple' | 'listId' | 'labelledBy' | 'entries' | 'activeId' | 'activeIndex' | 'navigationVersion' | 'virtualization' | 'classNames' | 'textOverflow' | 'popupStyle' | 'canCreate' | 'createId' | 'createLabel' | 'createActive'>
    handler: ComboboxOptionProps<T>['handler'] & Pick<ComboboxLogicResult<T>['handler'], 'handleCreateOption' | 'handleCreateActivate'>
    renderOption: ComboboxProps<T>['renderOption']
    loading?: boolean
    ariaLabel: string
}
ComboboxCreateOptionPropsinterface
  • @rentnerkev/select/combobox/types
ComboboxCreateOptionProps.d.ts
export interface ComboboxCreateOptionProps {
    state: Pick<ComboboxLogicResult<unknown>['state'], 'createId' | 'createLabel' | 'createActive' | 'classNames' | 'entries'>
    handler: Pick<ComboboxLogicResult<unknown>['handler'], 'handleCreateOption' | 'handleCreateActivate' | 'handleKeepFocus'>
}
VirtualComboboxOptionsLogicResultinterface
  • @rentnerkev/select/combobox/types
VirtualComboboxOptionsLogicResult.d.ts
export interface VirtualComboboxOptionsLogicResult<T> {
    state: {
        rows: ReadonlyArray<{
            item: VirtualItem
            entry: ComboboxEntry<T>
        }>
        totalSize: number
        height: number
    }
    refs: {
        viewport: RefObject<HTMLDivElement | null>
    }
    virtualizer: ReactVirtualizer<HTMLElement, HTMLElement>
}