跳转到内容
文档

文档Select

Select

单选或多选,始终得到正确的值。

@rentnerkev/select文档对应版本: v6.2.0

安装包

请使用 React 19,并在应用的全局 CSS 中导入一次包的样式表。附带的样式基于 Tailwind CSS 4。

Terminal
bun add @rentnerkev/select
全局样式表 / styles.css
@import '@rentnerkev/select/tailwind.css';

Combobox:多选对象与异步结果#

ComboboxProps<T> 是可辨识联合类型:multiple: true 时,value 为 readonly T[],onValueChange 接收 T[];单选模式保留 T | null。请独立控制 searchValue,并提供唯一且稳定的 getOptionKey 值。异步结果数组和对象更新后,已选对象仍会保留,即使当前页没有这些项目。默认通过键判断是否相等。filterMode external 显示应用传入的结果;数据请求、防抖、加载状态、取消和选项创建均由应用管理。

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>
    )
}

首次打开时的稳定定位与 ShadowRoot 传送容器#

CustomSelect 与 Combobox 共用弹层测量和显示就绪机制。当前弹层会先保持隐藏,直到在最终视口约束下完成测量,包括滚动条宽度,因此重新加载后的首次打开不会在过期坐标处闪现。滚动、视口变化及传送容器替换都会重新测量弹层。ShadowRoot 传送容器保留键盘焦点、整个控件离焦和外部点击关闭行为。

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>
    )
}

Select 与 Combobox 的选项分组#

在 CustomSelect 中设置 option.group,或通过 Combobox.getOptionGroup 返回组名。组标题不可选择;未分组的选项仍可使用。筛选、键盘导航、禁用选项和虚拟化均支持分组。可通过 classNames.group 和 groupLabel 自定义外观。

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>
    )
}

创建新的 Combobox 选项#

当去除首尾空白后的查询非空,且没有现有选项的标签与之相同(不区分大小写)时,onCreateOption 会显示创建行。createOptionLabel 可自定义行文本。回调接收去除首尾空白后的查询;创建、保存和选择选项由应用负责。禁用或只读控件不能创建选项。

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}
        />
    )
}

单独移除已选项#

在多选 CustomSelect 上启用 removableSelectedItems,即可在不打开弹出列表的情况下移除已选项。默认值为 false。悬停或键盘聚焦时会显示红色删除线和本地化提示;单击、Enter 或空格仅移除该值。禁用选项保持选中。disabled、readOnly 以及自定义 renderValue 会隐藏内置移除控件。

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:原生弹层迁移#

6.0.0 使用 React/DOM 弹层替代 Radix Select。组件导入和 props 保持不变。弹层为非模态:Tab 和 Shift+Tab 会关闭弹层并移至周围控件;外部点击会关闭弹层并激活目标。Escape 和单选完成后将焦点返回触发器。选项及 renderOption 内容仅在打开时挂载;关闭时的键入查找使用 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:外部搜索结果#

5.2.0 新增:Combobox<T> 接收业务对象,通过 getOptionKey 和 getOptionLabel 提供稳定唯一的键与标签。value 和 searchValue 分别受控:输入只改变查询,选择只改变值。如果选择后应以标签替换查询,请在选择处理函数中同时更新两者。filterMode 默认为 external,原样显示传入结果;local 启用标签过滤。请求、防抖和取消由应用负责。结果翻页不会清除选择。loading 隐藏旧结果,loadingText、emptyText 和 messages.loading 可自定义状态文本。

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}
        />
    )
}

文本插槽、换行与弹层宽度#

5.2.0 新增:controlSize sm/md/lg 分别设置 36/44/48 px;省略时保持原有尺寸。textOverflow 默认为 truncate,也可用 wrap 显示长文本。未固定尺寸的触发器可随换行增高;显式尺寸会保持所需高度。contentWidth 默认为 trigger,也支持 content,以触发器宽度为下限、视口为上限。optionLabel、optionDescription、optionIndicator、selectedLabel 和 selectedDescription 可直接设置文本样式,无需后代选择器。插槽替换默认视觉样式,嵌套 Provider 分别继承,空字符串移除默认样式。Combobox 用 search 设置输入框样式,缺省时回退到 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 的表单适配器#

/form 中的 getSelectFieldProps 将结构化字段连接至 CustomSelect 或 Combobox,不导入 React 或表单运行时。它返回 name、value、onValueChange、整个字段的 onBlur 和 error。默认在触碰后显示错误,errorVisibility 支持 touched、always 或 never。getReadableSelectError 接受字符串或带有字符串 message 的对象,mapError 可处理其他格式。null 错误明确将校验交由表单负责。应在订阅字段状态的渲染中调用;Combobox 仍需单独提供 searchValue 处理函数。

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' }]}
        />
    )
}

共享主题变量#

所有包共享 --rentner-* CSS 变量,包括 control、surface、foreground、muted、border、accent、accent-hover、accent-foreground、danger、success、warning、info 和 radius。Tailwind 入口会自动引入 theme.css;单独导出的 theme.css 仅包含主题变量,不包含完整的组件样式。全局主题可在 :root 上设置变量。局部主题还必须覆盖实际的 portal 目标。现有 customDesign 和旧主题变量仍受支持。

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;
}

本地 AI 辅助函数:元数据与指南#

在本地 Node.js 或 Bun 脚本中导入 /ai 入口。这些同步只读辅助函数通过 node:fs 读取已安装的软件包,无需导入其 UI。getPackageInfo() 返回 PackageInfo,包含已安装版本、公共导出和对等依赖。getPackageDocumentation() 返回带有 path 和 content 的 PackageDocument;默认值为 usage,readme 选择 README.md。仅接受这两个随包提供的文档。结果描述的是本地安装版本,可能与本网站不同。

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)

本地 AI 辅助函数:公共声明#

getPackageApi() 返回 PackageApi,包含 package、已安装的 version、选定的 subpaths 和由 PackageDocument 对象组成的 declarations。它读取带类型声明的公共入口及其本地声明依赖;不包含 /ai 本身。使用 . 或 ./types 等 subpath 选择公共入口。symbol 验证该入口是否导出指定名称;不会将声明文件裁剪为仅含该符号的内容。未知子路径、无效名称或选定入口未导出的名称会抛出错误。调用方不能提供任意文件路径。

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)
}

本地 AI 辅助函数:搜索与示例#

searchPackageDocumentation(query) 去除查询两端空白后,以不区分大小写的字面文本搜索 README.md 和 docs/usage.md。它返回 PackageSearchMatch 对象,包含 path、从一开始的 line 行号和匹配的 text;空查询返回空数组。getPackageExamples() 将已安装使用指南中的每个围栏代码块返回为含 language 和 code 的 PackageExample。这些辅助函数为你自己的工具提供文本,不会执行示例或联系 AI 服务。

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 与类型化选项#

传入包含 value 和 label 的 options,通过 value/onValueChange 控制选择。TValue 从选项值推断,可为字符串、数值或对象。选项可以包含辅助文本 subOption,以及用于禁止选择的 disabled。label、description、placeholder 和 icon 描述字段;fallbackOption 为不在选项列表中的已选值提供标签。

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}
        />
    )
}

多选与数量限制#

设置 multiple 并使用值数组。onValueChange 返回新数组。minSelection 和 maxSelection 定义数量限制;达到 maxSelection 后无法继续添加选项。required 和 error 用于验证。禁用选项无法被选中。

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}
        />
    )
}

可清除的值与 emptyValue#

要直接清除单选值,请结合 clearable 使用允许 null 的状态;清除时 onValueChange 返回 null。emptyValue 可指定其他空值标记,例如空字符串。单独管理清除逻辑时,仍可使用旧版 onClear 回调。多选清除后为空数组。

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}
        />
    )
}

搜索与键盘导航#

searchable 启用弹层内的搜索框;对于简短的固定列表可设为 false。控件支持键盘导航、选择和关闭。messages 自定义搜索标签、搜索占位文本和无结果提示。即使不显示可见标签,也应提供可访问的名称。

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}
        />
    )
}

对象值与相等判断#

当值为对象时,使用 isOptionEqualToValue 比较稳定的键,而不是对象引用。这样重新加载选项后仍能正确保留选择。getFormValue 将对象值序列化以用于原生表单。

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}
        />
    )
}

自定义选项与值的渲染#

renderOption 接收选项及其 selected/disabled 状态。renderValue 接收已选选项数组,单选模式下也是如此。返回 React 内容即可添加徽章或辅助信息,同时保留控件的键盘与选择行为。

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}
        />
    )
}

原生表单、焦点与字段状态#

name 创建原生表单值;getFormValue 将自定义值转换为字符串。多选字段提交多个同名值,可通过 FormData.getAll 读取。omitEmptyFormValue 忽略空的多选值。id、label、description、error、required 和 ARIA 属性描述验证状态。disabled 阻止交互,readOnly 禁止编辑。triggerRef 聚焦按钮,onBlur 跟踪离开字段的事件;组件样式需要 CSP nonce 时可通过 nonce 提供。

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#

为一组下拉选择器配置 locale、messages、classNames、searchable 和 nonce。组件自身设置优先于最近的 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()#

/value 辅助函数将空字符串、null 和 undefined 视为单选空值。它返回布尔值,并收窄 TypeScript 类型。

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

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

toggleSelectedValue()#

使用你的相等判断函数,在只读选择数组中切换一个值。已有值会被移除,新值会追加到末尾。如果添加后将超过 maxSelection,则返回 null。原数组不会被修改。

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

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

翻译与 resolveSelectMessages()#

selectMessageCatalog 包含 en、de、es 和 fr。resolveSelectMessages 将你的覆盖项与对应语言合并。消息涵盖必选项、最少和最多选择数、搜索、空状态及清除操作。minSelection 和 maxSelection 消息为接收数量参数的函数。

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,
})

样式类插槽与自定义设计#

className 设置组件外层样式。classNames 提供 root、trigger、content、search、viewport、option、empty、label、description 和 clear 插槽。只需指定要修改的插槽,并将共享默认值放在 SelectProvider 中。Tailwind 样式表只需导入一次。

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}
        />
    )
}

面向 AI 工具的文档

连接兼容的 MCP 客户端即可读取软件包 API、指南和示例。公开访问,无需账户或 API 密钥。

远程访问是可选的:请自行将此公共 URL 添加到 MCP 客户端。连接使用 Streamable HTTP;配置格式可能有所不同。本地 /ai 辅助函数在 Node.js 或 Bun 中读取已安装的软件包版本,绝不会自动连接此服务器。

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

工具:list_packages、read_package_docs、read_package_api、read_package_examples 和 search_package_docs。

API 与类型

此版本已发布的函数签名、属性和类型。展开条目即可查看定义及可用的导入路径。

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>
}