FilterBar
Filters for query pages: a keyword search (KeywordSearch) plus a row of filter chips (FilterChip), with the ones that don’t fit tucked into “More N”. A choice takes effect immediately; there is no “Search” button. Each chip gets an editor from its field type: select for single choice, multi for multiple choice (MultiEditor), tree for a tree (TreeEditor), intRange for a range (RangeEditor), dateRange / dateTimeRange for dates (DateRangeEditor). Works with tables, lists and cards.
Status: stable · Components: FilterBar, FilterChip, KeywordSearch, MultiEditor, TreeEditor, RangeEditor, DateRangeEditor, TextEditor, SkinnedCalendar
Import
Section titled “Import”import { FilterBar, FilterChip, KeywordSearch, MultiEditor, TreeEditor, RangeEditor, DateRangeEditor, TextEditor, SkinnedCalendar } from 'nacre'fields describes the fields, and values maps “field key → string value”; text / int fields merge into the search box on the left (keywordField remembers which one is searched), and each of the rest becomes a chip.
import { Text, View, signal } from 'nsh'import { FilterBar, TEXT_SIZE, TOUCH } from 'nacre'import type { FilterField, FilterValues } from 'nacre'
const issueTypes = () => [ { value: 'open', label: 'Account opening' }, { value: 'deposit', label: 'Deposit' }, { value: 'withdraw', label: 'Withdrawal' }, { value: 'trade', label: 'Trading' }, { value: 'security', label: 'Account security' },]
export function FilterBarUsage() { const fields: FilterField[] = [ { key: 'customer', label: 'Customer', type: 'text' }, { key: 'ticketNo', label: 'Ticket number', type: 'text' }, { key: 'state', label: 'Status', type: 'select', options: [ { value: 'open', label: 'In progress' }, { value: 'closed', label: 'Closed' }, ], }, { key: 'issue', label: 'Issue type', type: 'multi', options: issueTypes() }, { key: 'createdOn', label: 'Created on', type: 'dateRange' }, ] const values = signal<FilterValues>({}) const keywordField = signal('customer') return ( <View class="gap-2"> <View class="rounded-xl border border-border"> <FilterBar fields={fields} values={values()} onChange={(next) => values.set(next)} keywordField={keywordField()} onKeywordField={(key) => keywordField.set(key)} onRefresh={() => {}} onClear={() => values.set({})} /> </View> <Text class={`${TOUCH ? 'px-4' : ''} ${TEXT_SIZE.small} text-muted-foreground`}>{`$Applied ${Object.keys(values()).length}$ filters`}</Text> </View> )}Examples
Section titled “Examples”Chips and editors
Section titled “Chips and editors”With a value, a chip reads “Label: value”: long values are truncated with the full text on hover, and multi / tree read “first item +N”. Multi, tree and range take effect only after “Apply”; dates offer presets or a range picked on the calendar. A text field with chip: true uses TextEditor and commits on Return. DateRangeEditor uses SkinnedCalendar for the localized calendar.
Phone: On phones chips are 32 pills with a 44 tap area; long values truncate (open the editor to see them in full). Multi, tree and range editors apply only after “Apply”.
import { View, signal } from 'nsh'import { FilterChip } from 'nacre'import type { FilterField } from 'nacre'
const issueTypes = () => [ { value: 'open', label: 'Account opening' }, { value: 'deposit', label: 'Deposit' }, { value: 'withdraw', label: 'Withdrawal' }, { value: 'trade', label: 'Trading' }, { value: 'security', label: 'Account security' },]
const teams = () => [ { value: 'cs', label: 'Customer Service Center' }, { value: 'cs-hk', label: 'Hong Kong team', parent: 'cs' }, { value: 'cs-sg', label: 'Singapore team', parent: 'cs' }, { value: 'compliance', label: 'Compliance' }, { value: 'aml', label: 'AML team', parent: 'compliance' },]
function Chip(props: { field: FilterField; initial: string }) { const value = signal(props.initial) const open = signal(false) return ( <FilterChip field={props.field} value={value()} open={open()} onOpenChange={(next) => open.set(next)} onChange={(next) => value.set(next ?? '')} onRemove={() => value.set('')} /> )}
export function FilterChipEditors() { return ( <View class="flex-row flex-wrap items-center gap-2"> <Chip field={{ key: 'customerName', label: 'Customer name', type: 'text', chip: true }} initial="Longbridge Securities (Hong Kong) Limited Institutional Client Services High-Net-Worth Dedicated Line" /> <Chip field={{ key: 'issueType', label: 'Issue type', type: 'multi', options: issueTypes() }} initial="deposit,withdraw,trade" /> <Chip field={{ key: 'ownerTeam', label: 'Team', type: 'tree', options: teams() }} initial="cs-hk" /> <Chip field={{ key: 'waitMinutes', label: 'Queue time', type: 'intRange' }} initial="5," /> <Chip field={{ key: 'createdRange', label: 'Created on', type: 'dateRange' }} initial="2026-11-01,2026-11-20" /> </View> )}States
Section titled “States”An empty chip has only an outline; with a value it gets a fill, and a clear button appears on the right on hover or focus. required chips have no clear button; disabled chips can be neither opened nor cleared.
Phone: Empty chips are outlined; with a value they fill and always show a clear button; required chips have no clear; disabled chips can’t be opened or cleared.
import { View, signal } from 'nsh'import { FilterChip } from 'nacre'import type { FilterField } from 'nacre'
function Chip(props: { field: FilterField; initial: string }) { const value = signal(props.initial) const open = signal(false) return ( <FilterChip field={props.field} value={value()} open={open()} onOpenChange={(next) => open.set(next)} onChange={(next) => value.set(next ?? '')} onRemove={() => value.set('')} /> )}
export function FilterChipStates() { return ( <View class="flex-row flex-wrap items-center gap-2"> <Chip field={{ key: 'channelType', label: 'Channel', type: 'select', options: [{ value: 'app', label: 'App' }, { value: 'web', label: 'Web' }] }} initial="" /> <Chip field={{ key: 'period', label: 'Period', type: 'dateRange', required: true }} initial="2026-11-01,2026-11-24" /> <Chip field={{ key: 'market', label: 'Market', type: 'select', disabled: true, options: [{ value: 'hk', label: 'HK stocks' }] }} initial="hk" /> </View> )}Compact size and clear on reselect
Section titled “Compact size and clear on reselect”size=“xs” is 20 high with caption text, for a row of small text inside a panel or card (the record filters in the right panel); filter bars keep the default sm. clearOnReselect clears a single choice when its selected option is picked again. A disabled chip takes disabledReason, shown on hover to explain why it can’t be used. The value model is unchanged: multi is still a comma-joined string, and converting to and from arrays stays with the caller.
Phone: On phones xs is a 28 pill with 12 pt text; clearOnReselect and the value model work as on desktop.
import { View, signal } from 'nsh'import { FilterChip } from 'nacre'
export function FilterChipCompact() { const channel = signal('app') const channelOpen = signal(false) const status = signal('') const statusOpen = signal(false) const statuses = () => [ { value: 'resolved', label: 'Resolved' }, { value: 'unresolved', label: 'Unresolved' }, ] return ( <View class="flex-row flex-wrap items-center gap-1"> <FilterChip testID="filter-compact-channel" size="xs" clearOnReselect field={{ key: 'compactChannel', label: 'Channel', type: 'select', options: [{ value: 'app', label: 'App' }, { value: 'web', label: 'Web' }] }} value={channel()} open={channelOpen()} onOpenChange={(next) => channelOpen.set(next)} onChange={(next) => channel.set(next ?? '')} onRemove={() => channel.set('')} /> <FilterChip testID="filter-compact-status" size="xs" field={{ key: 'compactStatus', label: 'Status', type: 'multi', options: statuses() }} value={status()} open={statusOpen()} onOpenChange={(next) => statusOpen.set(next)} onChange={(next) => status.set(next ?? '')} onRemove={() => status.set('')} /> <FilterChip testID="filter-compact-locked" size="xs" field={{ key: 'compactLocked', label: 'End reason', type: 'multi', disabled: true, options: statuses() }} disabledReason="Only AI chats have an end reason" value="" open={false} onOpenChange={() => {}} onChange={() => {}} onRemove={() => {}} /> </View> )}KeywordSearch
Section titled “KeywordSearch”Merges several text fields into one search box, with a switch on the left for which one to search; it queries on Return and on clear, and int fields accept digits only. FilterBar has it built in; use it directly only on its own.
Phone: Several text fields share one search box, with a switcher on the left; it searches when you tap the keyboard’s search key or clear it, and int fields accept digits only.
import { Text, View, signal } from 'nsh'import { KeywordSearch, TEXT_SIZE } from 'nacre'import type { FilterField, FilterValues } from 'nacre'
export function KeywordSearchUsage() { const fields: FilterField[] = [ { key: 'nickname', label: 'Customer nickname', type: 'text' }, { key: 'accountNo', label: 'Account number', type: 'int' }, ] const values = signal<FilterValues>({}) const field = signal('nickname') return ( <View class="gap-2"> <KeywordSearch fields={fields} field={field()} onField={(key) => field.set(key)} values={values()} onSearch={(next) => values.set(next)} /> <Text class={`${TEXT_SIZE.small} text-muted-foreground`}>{`$Query: ${Object.entries(values()).map(([key, value]) => `${key}=${value}`).join(', ') || '—'}`}</Text> </View> )}Collapsed
Section titled “Collapsed”mode=“collapsed” is for narrow areas such as cards and drawers: the tool row has a single “Filter” button (with the number of active filters); it opens a list of fields, and the chosen field appears as a chip on the next row with its editor open. Active filters are removable chips, and with none the row is gone. It has no outer padding; the caller places it.
import { View, signal } from 'nsh'import { FilterBar, TOUCH } from 'nacre'import type { FilterField, FilterValues } from 'nacre'
const issueTypes = () => [ { value: 'open', label: 'Account opening' }, { value: 'deposit', label: 'Deposit' }, { value: 'withdraw', label: 'Withdrawal' }, { value: 'trade', label: 'Trading' }, { value: 'security', label: 'Account security' },]
export function FilterBarCollapsed() { const fields: FilterField[] = [ { key: 'status', label: 'Status', type: 'select', options: [ { value: 'open', label: 'In progress' }, { value: 'closed', label: 'Closed' }, ], }, { key: 'issue', label: 'Issue type', type: 'multi', options: issueTypes() }, { key: 'createdOn', label: 'Created on', type: 'dateRange' }, ] const values = signal<FilterValues>({ status: 'open' }) return ( <View testID="filter-collapsed" class={`${TOUCH ? 'w-full' : 'w-[360px] max-w-full rounded-xl border border-border'} p-3`}> <FilterBar mode="collapsed" fields={fields} values={values()} onChange={(next) => values.set(next)} /> </View> )}When chips don’t fit
Section titled “When chips don’t fit”Chips stay on one row by default, and the ones that don’t fit go into “More N”, which expands on click and collapses on a second click; chips with a value always stay in the visible row, and pinned ones are kept first. memoryKey remembers the expanded state per page for the current run.
import { View, signal } from 'nsh'import { FilterBar } from 'nacre'import type { FilterField, FilterValues } from 'nacre'
export function FilterBarOverflow() { const option = (value: string, label = value) => ({ value, label }) const fields: FilterField[] = [ { key: 'sessionId', label: 'Chat ID', type: 'text' }, { key: 'agentName', label: 'Agent', type: 'select', options: [option('林嘉怡', 'Lin Jiayi'), option('陈智源', 'Chen Zhiyuan')], pinned: true, }, { key: 'source', label: 'Source', type: 'select', options: [option('App'), option('网页', 'Web'), option('WhatsApp')] }, { key: 'priority', label: 'Priority', type: 'select', options: [option('高', 'High'), option('中', 'Medium'), option('低', 'Low')], }, { key: 'region', label: 'Region', type: 'select', options: [option('香港', 'Hong Kong'), option('新加坡', 'Singapore'), option('美国', 'United States')], }, { key: 'language', label: 'Language', type: 'select', options: [option('中文', 'Chinese'), option('English')] }, { key: 'satisfaction', label: 'Satisfaction', type: 'select', options: [option('满意', 'Satisfied'), option('一般', 'Neutral'), option('不满意', 'Dissatisfied')], }, { key: 'tagName', label: 'Tags', type: 'multi', options: [option('开户', 'Account opening'), option('入金', 'Deposit'), option('投诉', 'Complaint')], }, { key: 'duration', label: 'Duration (min)', type: 'intRange', required: true }, { key: 'closedAt', label: 'Closed at', type: 'dateTimeRange' }, ] const values = signal<FilterValues>({}) const keywordField = signal('sessionId') return ( <View class="rounded-xl border border-border"> <FilterBar fields={fields} values={values()} onChange={(next) => values.set(next)} keywordField={keywordField()} onKeywordField={(key) => keywordField.set(key)} memoryKey="docs-filter-overflow" onClear={() => values.set({})} /> </View> )}Keyboard
Section titled “Keyboard”| Key | Action |
|---|---|
| Tab | Move between the search box, chips, “More” and Refresh / Clear |
| Return | In the search box, text editor or range editor: submit |
| Backspace / Delete | Clear the focused chip’s value (except required and disabled chips) |
| Esc | Close the editor and return focus to the chip |
Accessibility
Section titled “Accessibility”- A chip’s screen reader name is “Label: value” (“Issue type: Deposit +2”); an empty chip reads only its label.
- The clear button reads “Clear”; the field switch on the left of the keyword search reads as a button named after the current field.
- While an editor is open, the table’s global ↑↓ ⏎ go to the editor.
- A chip reads as a button and reports expanded; a disabled chip reads as disabled, with disabledReason as its hover tip.
Do / Don’t
Section titled “Do / Don’t”Do
- Apply a value as soon as it’s chosen
- Truncate long values and show the full text on hover
- Pin common filters so they stay in the first row
- Offer “Clear filters” in the table when there are no results
Don’t
- Build filters as a form with a Search button
- Make required filters clearable
- Put two filter bars on one page
Property descriptions follow the Chinese source comments.
FilterBar
Section titled “FilterBar”| Prop | Type | Default | Description |
|---|---|---|---|
fields * |
FilterField[] |
— | |
values * |
FilterValues |
— | |
onChange * |
(values: FilterValues) => void |
— | |
mode |
'inline' | 'collapsed' |
— | inline(默认):关键词框 + 平铺芯片,放不下的收进「更多 N」,查询页的筛选栏。 collapsed:工具行只有一个「筛选」按钮(带生效条件数),点开逐项挑字段再编辑,生效条件以可删芯片排在下一行、没有条件不出这一行; 不带外边距,嵌在卡片、抽屉这类窄区域里。创建时读一次 |
keywordField |
string |
— | 关键词框选中的字段,由调用方持久化(inline) |
onKeywordField |
(key: string) => void |
— | |
keywordRef |
(node: InputRef) => void |
— | |
memoryKey |
string |
— | 「更多」展开态在本次运行内按它记忆(每页一个),不进 Storage |
onRefresh |
() => void |
— | |
refreshing |
boolean |
— | |
onClear |
() => void |
— | |
leading |
JSX.Element |
— | |
tools |
JSX.Element |
— | 刷新与清空之间的工具位(常用筛选) |
trailing |
JSX.Element |
— | 右侧:表格设置、导出等 |
* required
FilterChip
Section titled “FilterChip”| Prop | Type | Default | Description |
|---|---|---|---|
field * |
FilterField |
— | |
value * |
string |
— | 字段值(同 FilterBar 的 values):多选 / 树形是逗号拼接,区间与日期是 start,end |
open * |
boolean |
— | |
onOpenChange * |
(open: boolean) => void |
— | |
onChange * |
(value: string | undefined) => void |
— | |
onRemove * |
() => void |
— | |
size |
'xs' | 'sm' |
'sm' |
sm 28(默认,筛选栏)/ xs 20(嵌在面板、卡片的一行小字里:右栏记录筛选),内边距与圆角读 xs 结构 token |
clearOnReselect |
boolean |
— | 单选(select)再点已选项清空(onChange(undefined));默认再点保持不变 |
disabledReason |
string |
— | 禁用(field.disabled)时悬停芯片看到的原因:「先清掉会话状态」这类 |
testID |
string |
— | 芯片的 testID,默认 filter-chip-${field.key};给了时编辑器是 ${testID}-options |
* required
KeywordSearch
Section titled “KeywordSearch”| Prop | Type | Default | Description |
|---|---|---|---|
fields * |
FilterField[] |
— | 文本类字段(text / int) |
field * |
string |
— | 选中的字段 key,空时取第一个;由调用方持久化 |
onField * |
(key: string) => void |
— | |
values * |
FilterValues |
— | |
onSearch * |
(values: FilterValues) => void |
— | 回车、清空时:文本字段只保留选中的那一个 |
inputRef |
(node: InputRef) => void |
— |
* required
MultiEditor
Section titled “MultiEditor”| Prop | Type | Default | Description |
|---|---|---|---|
field * |
FilterField |
— | |
value * |
string |
— | |
onChange * |
(value: string | undefined) => void |
— | |
onDone * |
() => void |
— | |
anchorWidth |
number |
— | |
testID |
string |
— | 编辑器根节点的 testID,默认 filter-editor-${field.key};多选的「应用」「清空」在它后面加 -apply / -clear |
* required
TreeEditor
Section titled “TreeEditor”| Prop | Type | Default | Description |
|---|---|---|---|
field * |
FilterField |
— | |
value * |
string |
— | |
onChange * |
(value: string | undefined) => void |
— | |
onDone * |
() => void |
— | |
anchorWidth |
number |
— | |
testID |
string |
— | 编辑器根节点的 testID,默认 filter-editor-${field.key};多选的「应用」「清空」在它后面加 -apply / -clear |
* required
RangeEditor
Section titled “RangeEditor”| Prop | Type | Default | Description |
|---|---|---|---|
field * |
FilterField |
— | |
value * |
string |
— | |
onChange * |
(value: string | undefined) => void |
— | |
onDone * |
() => void |
— | |
anchorWidth |
number |
— | |
testID |
string |
— | 编辑器根节点的 testID,默认 filter-editor-${field.key};多选的「应用」「清空」在它后面加 -apply / -clear |
* required
DateRangeEditor
Section titled “DateRangeEditor”| Prop | Type | Default | Description |
|---|---|---|---|
testID * |
string |
— | |
value * |
string |
— | start,end:日期 YYYY-MM-DD,带时间时 YYYY-MM-DD HH:mm |
withTime |
boolean |
— | |
granularity |
'minute' | 'hour' |
— | 带时间时的粒度:hour 只取整点(HH:00),结束默认 23:00 |
maxDate |
string |
— | 最晚可选的日期 YYYY-MM-DD,之后的日子置灰 |
isValid |
(draft: string) => boolean |
— | 草稿(同 value 的格式)不合法时「应用」置灰 |
presets * |
readonly DatePreset[] |
— | 空数组时不渲染快捷区间一行 |
onApply * |
(value: string | undefined) => void |
— | |
footnote |
JSX.Element |
— |
* required
TextEditor
Section titled “TextEditor”| Prop | Type | Default | Description |
|---|---|---|---|
field * |
FilterField |
— | |
value * |
string |
— | |
onChange * |
(value: string | undefined) => void |
— | |
onDone * |
() => void |
— | |
anchorWidth |
number |
— | |
testID |
string |
— | 编辑器根节点的 testID,默认 filter-editor-${field.key};多选的「应用」「清空」在它后面加 -apply / -clear |
* required
SkinnedCalendar
Section titled “SkinnedCalendar”| Prop | Type | Default | Description |
|---|---|---|---|
testID |
string |
— | |
range |
boolean |
— | |
value * |
CalendarValue |
— | |
numberOfMonths |
number |
1 |
|
maxDate |
string |
— | 最晚可选的日期 YYYY-MM-DD,之后的日子置灰、不可点 |
paint |
(date: string) => DayPaint |
— | 区间自己画(DateRangeEditor):给了就不用 Calendar 的选中样式 |
onHoverDate |
(date: string | null) => void |
— | |
onChange * |
(value: CalendarValue) => void |
— |
* required