Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

refactor(quill): build the search filter on Base UI's filterable menu (#128813)

Adam Leith0a42bb80e94f
diff --git a/frontend/src/design.md b/frontend/src/design.md
index 990ba954dcb3..b2d393f55f94 100644
--- a/frontend/src/design.md
+++ b/frontend/src/design.md
@@ -61,7 +61,7 @@ Compose from the listed parts only. Part names are shown without their prefix (e
- Dialog (Trigger, Content, Header, Title, Description, Body, Footer, Close, Overlay, Portal)
- Dot
- Drawer (Trigger, Content, Header, Title, Description, Footer, Close, Handle, Backdrop, Portal)
-- DropdownMenu (Trigger, Content, Item, CheckboxItem, RadioGroup, RadioItem, SelectAll, Label, Separator, Shortcut, Group, Sub, SubTrigger, SubContent, Portal; useDropdownMenuSelectAll)
+- DropdownMenu (Trigger, Content, Item, CheckboxItem, RadioGroup, RadioItem, SelectAll, Label, Separator, Shortcut, Group, Sub, SubTrigger, SubContent, Portal, FilterProvider, Input, Empty, List; useDropdownMenuSelectAll)
- Empty (Header, Media, Title, Description, Content)
- IconStack (Item)
- Field (Label, Description, Error, Group, Set, Legend, Separator, Content, Title)
@@ -198,6 +198,7 @@ Use via Tailwind utilities (`bg-primary text-primary-foreground`, `border-border
- Combobox: one or many values from a long or async list, filterable; multi-select shows chips; no free text
- Actions in a Combobox (settings, "New …") are list items, never footer buttons. See section 8
- Autocomplete: free text with optional suggestions; search, command pickers
+ - Filterable DropdownMenu (`DropdownMenuFilterProvider`, `DropdownMenuInput`, `DropdownMenuEmpty`, `DropdownMenuList`): search the rows of a menu or submenu that is already open, such as a list's filter menu. Use Combobox instead when the control is a field that holds a value, needs chips, or lists more than about 1,000 options, because a filterable menu keeps every row mounted
- Picking an action:
- DropdownMenu: click-triggered list of actions
- ContextMenu: right-click only; never the only path to an action
diff --git a/frontend/src/scenes/analytics/AnalyticsFilterMenu.tsx b/frontend/src/scenes/analytics/AnalyticsFilterMenu.tsx
index f85db8d8abed..cbea0da031ea 100644
--- a/frontend/src/scenes/analytics/AnalyticsFilterMenu.tsx
+++ b/frontend/src/scenes/analytics/AnalyticsFilterMenu.tsx
@@ -1,4 +1,5 @@
import { useActions, useValues } from 'kea'
+import posthog from 'posthog-js'
import { IconTrends } from '@posthog/icons'
import {
@@ -8,6 +9,7 @@ import {
DropdownMenuSeparator,
FilterCheckboxSubMenu,
FilterClearItem,
+ FilterMenuOpenTiming,
FilterMenuTrigger,
FilterOption,
FilterRadioSubMenu,
@@ -55,6 +57,17 @@ const TYPE_OPTIONS: FilterOption<AnalyticsType>[] = ANALYTICS_TYPES.map((info) =
),
}))
+function captureFilterMenuOpened(
+ menu: 'analytics-tags' | 'analytics-created-by',
+ { durationMs, optionCount }: FilterMenuOpenTiming
+): void {
+ posthog.capture('filter menu opened', {
+ menu,
+ duration_ms: Math.round(durationMs),
+ option_count: optionCount,
+ })
+}
+
/**
* The list's controls in one menu, laid out like the nav rail's: sort, then a row per filter, then display choices, then
* Clear filters. The sort and display choices are saved on the person, so they never count as a filter.
@@ -124,6 +137,7 @@ export function AnalyticsFilterMenu(): JSX.Element {
searchPlaceholder="Search people"
emptyText="No one matches"
onOpen={ensureAllMembersLoaded}
+ onOpened={(timing) => captureFilterMenuOpened('analytics-created-by', timing)}
dataAttr="analytics-list-created-by"
optionDataAttr="analytics-list-created-by-option"
/>
@@ -139,6 +153,7 @@ export function AnalyticsFilterMenu(): JSX.Element {
searchPlaceholder="Search tags"
emptyText="No tag matches"
onOpen={loadTagsIfNeeded}
+ onOpened={(timing) => captureFilterMenuOpened('analytics-tags', timing)}
dataAttr="analytics-list-tags"
optionDataAttr="analytics-list-tags-option"
/>
diff --git a/packages/quill/packages/components/AGENTS.md b/packages/quill/packages/components/AGENTS.md
index 47857822fe3d..40e3c0cdb2eb 100644
--- a/packages/quill/packages/components/AGENTS.md
+++ b/packages/quill/packages/components/AGENTS.md
@@ -87,6 +87,7 @@ Rules:
- One choice → `FilterRadioSubMenu`. Several from a short list → `FilterCheckboxSubMenu`. Several from a long list → `FilterSearchSubMenu`.
- An empty selection means all of them. Pass `defaultValue` on a radio filter so that a change takes the primary color. Leave it out on a row that isn't a filter, such as a sort.
+- To measure a long list, pass `onOpened` to `FilterSearchSubMenu`. It reports how long the submenu took to paint and how many options it listed, because every row stays mounted.
- `active` covers filters only. A sort, a display choice or the search text never lights the dot.
## DateTimePicker
diff --git a/packages/quill/packages/components/src/filter-menu.stories.tsx b/packages/quill/packages/components/src/filter-menu.stories.tsx
index 363b5bd4a1f5..f56918e9f0f9 100644
--- a/packages/quill/packages/components/src/filter-menu.stories.tsx
+++ b/packages/quill/packages/components/src/filter-menu.stories.tsx
@@ -73,3 +73,28 @@ export const Default: Story = {
)
},
}
+
+const MANY_TAGS = Array.from({ length: 1000 }, (_, index) => ({ value: `tag-${index}`, label: `tag-${index}` }))
+
+export const ManySearchOptions: Story = {
+ render: function Render() {
+ const [tags, setTags] = React.useState<string[]>([])
+ return (
+ <DropdownMenu>
+ <FilterMenuTrigger active={tags.length > 0} />
+ <DropdownMenuContent align="start" className="min-w-64">
+ <FilterSearchSubMenu
+ label="Tags"
+ allLabel="Any tag"
+ pluralNoun="tags"
+ options={MANY_TAGS}
+ selected={tags}
+ onChange={setTags}
+ searchPlaceholder="Search tags"
+ emptyText="No tag matches"
+ />
+ </DropdownMenuContent>
+ </DropdownMenu>
+ )
+ },
+}
diff --git a/packages/quill/packages/components/src/filter-menu.test.tsx b/packages/quill/packages/components/src/filter-menu.test.tsx
index 35e9c5fa4b14..11e9f2544426 100644
--- a/packages/quill/packages/components/src/filter-menu.test.tsx
+++ b/packages/quill/packages/components/src/filter-menu.test.tsx
@@ -1,4 +1,4 @@
-import { act, cleanup, fireEvent, render, screen } from '@testing-library/react'
+import { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
import { DropdownMenu, DropdownMenuContent, DropdownMenuTrigger } from '@posthog/quill-primitives'
@@ -70,7 +70,8 @@ describe('FilterSearchSubMenu', () => {
expect(onOpen).toHaveBeenCalledTimes(1)
})
- it('caps the rows until a search narrows them', async () => {
+ it('reports how long the submenu took to open', async () => {
+ const onOpened = jest.fn()
render(
<DropdownMenu defaultOpen>
<DropdownMenuTrigger>Filters</DropdownMenuTrigger>
@@ -79,12 +80,10 @@ describe('FilterSearchSubMenu', () => {
label="Tags"
allLabel="Any tag"
pluralNoun="tags"
- options={Array.from({ length: 300 }, (_, index) => ({
- value: `tag-${index}`,
- label: `tag-${index}`,
- }))}
+ options={[]}
selected={[]}
onChange={jest.fn()}
+ onOpened={onOpened}
searchPlaceholder="Search tags"
emptyText="No tag matches"
/>
@@ -95,17 +94,47 @@ describe('FilterSearchSubMenu', () => {
await act(async () => {
fireEvent.click(await screen.findByText('Tags'))
})
- const input = await screen.findByLabelText('Search tags')
- expect(screen.getAllByRole('option')).toHaveLength(200)
- expect(screen.getByText('Keep typing to see more')).toBeTruthy()
- expect(screen.queryByText('tag-299')).toBeNull()
+ await waitFor(() => expect(onOpened).toHaveBeenCalledTimes(1))
+ expect(onOpened).toHaveBeenCalledWith({ durationMs: expect.any(Number), optionCount: 0 })
+ })
+
+ it('adds a picked row to the selection and keeps the menu open', async () => {
+ const onChange = jest.fn()
+ render(
+ <DropdownMenu defaultOpen>
+ <DropdownMenuTrigger>Filters</DropdownMenuTrigger>
+ <DropdownMenuContent>
+ <FilterSearchSubMenu
+ label="Tags"
+ allLabel="Any tag"
+ pluralNoun="tags"
+ options={[
+ { value: 'growth', label: 'growth' },
+ { value: 'revenue', label: 'revenue' },
+ ]}
+ selected={['growth']}
+ onChange={onChange}
+ searchPlaceholder="Search tags"
+ emptyText="No tag matches"
+ />
+ </DropdownMenuContent>
+ </DropdownMenu>
+ )
+ await act(async () => {
+ fireEvent.click(await screen.findByText('Tags'))
+ })
+ const input = await screen.findByLabelText('Search tags')
+ await act(async () => {
+ fireEvent.change(input, { target: { value: 'rev' } })
+ })
+ expect(screen.getAllByRole('menuitemcheckbox').map((row) => row.textContent)).toEqual(['revenue'])
await act(async () => {
- fireEvent.change(input, { target: { value: 'tag-299' } })
+ fireEvent.click(screen.getByText('revenue'))
})
- expect(screen.getByText('tag-299')).toBeTruthy()
- expect(screen.queryByText('Keep typing to see more')).toBeNull()
+ expect(onChange).toHaveBeenCalledWith(['growth', 'revenue'])
+ expect(screen.getByLabelText('Search tags')).toBeTruthy()
})
})
diff --git a/packages/quill/packages/components/src/filter-menu.tsx b/packages/quill/packages/components/src/filter-menu.tsx
index 1aaa6e4f900b..26cd4ce25e6d 100644
--- a/packages/quill/packages/components/src/filter-menu.tsx
+++ b/packages/quill/packages/components/src/filter-menu.tsx
@@ -4,13 +4,12 @@ import * as React from 'react'
import {
Button,
cn,
- Combobox,
- ComboboxEmpty,
- ComboboxInput,
- ComboboxItem,
- ComboboxList,
DropdownMenuCheckboxItem,
+ DropdownMenuEmpty,
+ DropdownMenuFilterProvider,
+ DropdownMenuInput,
DropdownMenuItem,
+ DropdownMenuList,
DropdownMenuRadioGroup,
DropdownMenuRadioItem,
DropdownMenuSeparator,
@@ -21,7 +20,6 @@ import {
Tooltip,
TooltipContent,
TooltipTrigger,
- useComboboxFilteredItems,
} from '@posthog/quill-primitives'
export interface FilterOption<Value extends string = string> {
@@ -32,6 +30,11 @@ export interface FilterOption<Value extends string = string> {
hint?: string
}
+export interface FilterMenuOpenTiming {
+ durationMs: number
+ optionCount: number
+}
+
/** What a filter row shows for several values: the default, up to two labels, or a count, such as "3 tags". */
export function filterSummary(labels: string[], allLabel: string, pluralNoun: string): string {
if (labels.length === 0) {
@@ -141,6 +144,71 @@ export function FilterRadioSubMenu<Value extends string>({
)
}
+/** The row for "all of them", the empty selection. */
+function FilterAllRow({
+ label,
+ icon,
+ checked,
+ onSelect,
+ dataAttr,
+}: {
+ label: string
+ icon?: React.ReactNode
+ checked: boolean
+ onSelect: () => void
+ dataAttr?: string
+}): React.ReactElement {
+ return (
+ <DropdownMenuCheckboxItem
+ label={label}
+ checked={checked}
+ closeOnClick={false}
+ onCheckedChange={onSelect}
+ title={label}
+ data-attr={dataAttr}
+ >
+ {icon}
+ <span className="truncate">{label}</span>
+ </DropdownMenuCheckboxItem>
+ )
+}
+
+function FilterOptionRows<Value extends string>({
+ options,
+ selected,
+ onChange,
+ dataAttr,
+}: {
+ options: readonly FilterOption<Value>[]
+ selected: readonly Value[]
+ onChange: (selected: Value[]) => void
+ dataAttr?: string
+}): React.ReactElement {
+ return (
+ <>
+ {options.map((option) => (
+ <DropdownMenuCheckboxItem
+ key={option.value}
+ label={option.label}
+ checked={selected.includes(option.value)}
+ closeOnClick={false}
+ onCheckedChange={(checked) =>
+ onChange(
+ checked ? [...selected, option.value] : selected.filter((value) => value !== option.value)
+ )
+ }
+ title={option.label}
+ data-attr={dataAttr}
+ >
+ {option.icon}
+ <span className="truncate">{option.label}</span>
+ {option.hint && <span className="ml-auto text-xs text-muted-foreground">{option.hint}</span>}
+ </DropdownMenuCheckboxItem>
+ ))}
+ </>
+ )
+}
+
/** A filter with several choices from a short list. An empty selection means all of them. */
export function FilterCheckboxSubMenu<Value extends string>({
label,
@@ -171,49 +239,19 @@ export function FilterCheckboxSubMenu<Value extends string>({
active={selected.length > 0}
dataAttr={dataAttr}
>
- <DropdownMenuCheckboxItem
+ <FilterAllRow
+ label={allLabel}
+ icon={allIcon}
checked={selected.length === 0}
- closeOnClick={false}
- onCheckedChange={() => onChange([])}
- data-attr={optionDataAttr}
- >
- {allIcon}
- {allLabel}
- </DropdownMenuCheckboxItem>
+ onSelect={() => onChange([])}
+ dataAttr={optionDataAttr}
+ />
<DropdownMenuSeparator />
- {options.map((option) => (
- <DropdownMenuCheckboxItem
- key={option.value}
- checked={selected.includes(option.value)}
- closeOnClick={false}
- onCheckedChange={(checked) =>
- onChange(
- checked ? [...selected, option.value] : selected.filter((value) => value !== option.value)
- )
- }
- data-attr={optionDataAttr}
- >
- {option.icon}
- {option.label}
- </DropdownMenuCheckboxItem>
- ))}
+ <FilterOptionRows options={options} selected={selected} onChange={onChange} dataAttr={optionDataAttr} />
</FilterSubMenu>
)
}
-// The search field and rows sit in the menu's popup, whose own key and click handling would close the menu or steal them.
-const stopPropagation = (event: React.SyntheticEvent): void => event.stopPropagation()
-
-type SearchOption = FilterOption<string> | { value: null; label: string; icon?: undefined; hint?: undefined }
-
-// Each row is a mounted component, and opening the menu slows past a few hundred of them.
-const SEARCH_OPTION_LIMIT = 200
-
-function SearchLimitHint(): React.ReactElement | null {
- const reachedLimit = useComboboxFilteredItems().length >= SEARCH_OPTION_LIMIT
- return reachedLimit ? <div className="p-2 text-xs text-muted-foreground">Keep typing to see more</div> : null
-}
-
/** A filter with several choices from a long list, such as people or tags. An empty selection means all of them. */
export function FilterSearchSubMenu({
label,
@@ -226,6 +264,7 @@ export function FilterSearchSubMenu({
searchPlaceholder,
emptyText,
onOpen,
+ onOpened,
dataAttr,
optionDataAttr,
}: {
@@ -240,90 +279,66 @@ export function FilterSearchSubMenu({
emptyText: string
/** Called when the submenu opens, to load its options only once someone wants them. */
onOpen?: () => void
+ /** Called once the open submenu has painted, with how long that took and how many options it listed. */
+ onOpened?: (timing: FilterMenuOpenTiming) => void
dataAttr?: string
optionDataAttr?: string
}): React.ReactElement {
- const allOption: SearchOption = { value: null, label: allLabel }
// Values the options do not know yet, such as a tag from the URL before the list loads, still count as picked.
const unknown = selected.filter((value) => !options.some((option) => option.value === value))
const known: FilterOption[] = [...options, ...unknown.map((value) => ({ value, label: value }))]
const picked = known.filter((option) => selected.includes(option.value))
+ const handleOpenChange = (open: boolean): void => {
+ if (!open) {
+ return
+ }
+ onOpen?.()
+ if (onOpened) {
+ const startedAt = performance.now()
+ // The first frame runs after the rows have rendered, and the second after they have painted.
+ requestAnimationFrame(() =>
+ requestAnimationFrame(() =>
+ onOpened({ durationMs: performance.now() - startedAt, optionCount: known.length })
+ )
+ )
+ }
+ }
return (
- <DropdownMenuSub onOpenChange={(open) => open && onOpen?.()}>
- <FilterSubMenuRow
- label={label}
- value={filterSummary(
- picked.map((option) => option.label),
- allLabel,
- pluralNoun
- )}
- active={selected.length > 0}
- dataAttr={dataAttr}
- />
- {/* Flush because the list scrolls on its own, under a search field that stays put. */}
- <DropdownMenuSubContent flush className="w-64">
- <Combobox<SearchOption, true>
- multiple
- // The submenu is the popup, so the list is always open and a pick resets the search.
- inline
- autoHighlight
- limit={SEARCH_OPTION_LIMIT}
- items={[allOption, ...known]}
- itemToStringValue={(option) => option.label}
- isItemEqualToValue={(option, other) => option.value === other.value}
- value={picked.length > 0 ? picked : [allOption]}
- onValueChange={(next, { reason }) => {
- // The list counts as closed while inline, so Base UI treats Escape as a request to clear.
- if (reason === 'escape-key') {
- return
- }
- // While nothing is picked, "all" is the ticked row, so ticking a value also carries it along.
- const allTicked = next.some((option) => option.value === null)
- onChange(
- allTicked && selected.length > 0
- ? []
- : next.flatMap((option) => (option.value === null ? [] : [option.value]))
- )
- }}
- >
- <div className="p-1">
- <ComboboxInput
- autoFocus
- showTrigger={false}
- placeholder={searchPlaceholder}
- aria-label={searchPlaceholder}
- data-compact=""
- onClick={stopPropagation}
- onKeyDown={(event) => {
- if (event.key !== 'Escape') {
- event.stopPropagation()
- }
- }}
+ <DropdownMenuFilterProvider autoHighlight>
+ <DropdownMenuSub onOpenChange={handleOpenChange}>
+ <FilterSubMenuRow
+ label={label}
+ value={filterSummary(
+ picked.map((option) => option.label),
+ allLabel,
+ pluralNoun
+ )}
+ active={selected.length > 0}
+ dataAttr={dataAttr}
+ />
+ {/* Flush because the list scrolls on its own, under a search field that stays put. */}
+ <DropdownMenuSubContent flush className="w-64">
+ {/* Autofocus because Base UI leaves the focus on the row when hover opens the submenu, and typing would go nowhere. */}
+ <DropdownMenuInput autoFocus placeholder={searchPlaceholder} aria-label={searchPlaceholder} />
+ <DropdownMenuEmpty>{emptyText}</DropdownMenuEmpty>
+ <DropdownMenuList>
+ <FilterAllRow
+ label={allLabel}
+ checked={selected.length === 0}
+ onSelect={() => onChange([])}
+ dataAttr={optionDataAttr}
/>
- </div>
- <ComboboxEmpty>{emptyText}</ComboboxEmpty>
- <ComboboxList>
- {(option: SearchOption) => (
- <ComboboxItem
- key={option.value ?? 'all'}
- value={option}
- title={option.label}
- onClick={stopPropagation}
- data-attr={optionDataAttr}
- >
- {option.icon}
- <span className="truncate">{option.label}</span>
- {option.hint && (
- <span className="ml-auto text-xs text-muted-foreground">{option.hint}</span>
- )}
- </ComboboxItem>
- )}
- </ComboboxList>
- <SearchLimitHint />
+ <FilterOptionRows
+ options={known}
+ selected={selected}
+ onChange={onChange}
+ dataAttr={optionDataAttr}
+ />
+ </DropdownMenuList>
{loading && <div className="p-2 text-xs text-muted-foreground">Loading…</div>}
- </Combobox>
- </DropdownMenuSubContent>
- </DropdownMenuSub>
+ </DropdownMenuSubContent>
+ </DropdownMenuSub>
+ </DropdownMenuFilterProvider>
)
}
diff --git a/packages/quill/packages/components/src/index.ts b/packages/quill/packages/components/src/index.ts
index af086a17b066..b6371a5a1427 100644
--- a/packages/quill/packages/components/src/index.ts
+++ b/packages/quill/packages/components/src/index.ts
@@ -13,6 +13,7 @@ export {
FilterCheckboxSubMenu,
FilterClearItem,
FilterMenuTrigger,
+ type FilterMenuOpenTiming,
type FilterOption,
FilterRadioSubMenu,
FilterSearchSubMenu,
diff --git a/packages/quill/packages/primitives/AGENTS.md b/packages/quill/packages/primitives/AGENTS.md
index f9de63223900..91c53e3c030d 100644
--- a/packages/quill/packages/primitives/AGENTS.md
+++ b/packages/quill/packages/primitives/AGENTS.md
@@ -66,6 +66,8 @@ Pick by intent, not appearance. Each cluster below lists the discriminating ques
| Combobox | Pick one or many values from a long/dynamic list, with search. Multi-select renders chips | Action menus |
| Autocomplete | Search-first text input with suggestions where the typed text itself is the value | Constrained choices — use Select/Combobox |
+To search a menu's rows, wrap `DropdownMenu` or `DropdownMenuSub` in `DropdownMenuFilterProvider`, then add `DropdownMenuInput` and `DropdownMenuEmpty`, and put the rows in `DropdownMenuList`. Base UI marks this API as a preview.
+
For a custom menu-like list inside a Popover (when DropdownMenu's open/close semantics don't fit), use `Item variant="menuItem"` with `ItemMenuItem`/`ItemCheckbox`/`ItemRadio` — don't restyle Buttons into menu rows. Inside quill, a primitive that renders a Button as a list row passes `size="row"` rather than pinning width, weight and text size per caller. `MenuLabel` is the shared section-label primitive the menu families render internally (DropdownMenuLabel, ComboboxLabel); it's exported for these custom menu-like lists.
Every menu-like list marks its active row the same way: the row that keyboard input or a filter would act on (`data-highlighted`) gets a ring, and a row under the pointer gets the plain hover fill. Don't override this per component.
diff --git a/packages/quill/packages/primitives/src/combobox.css b/packages/quill/packages/primitives/src/combobox.css
index 5f50a677cd1b..3ba5b1c5fc70 100644
--- a/packages/quill/packages/primitives/src/combobox.css
+++ b/packages/quill/packages/primitives/src/combobox.css
@@ -132,10 +132,8 @@
* keeps Button's own padding. The gutter is the row's padding, an icon and
* the item's gap, so an option's content starts exactly where an action
* row's label does. The gap lives in one variable, so the two cannot drift.
- * A Combobox can also sit in a menu's submenu, with no popup of its own.
*/
- :is(.quill-combobox__content, .quill-menu__content, .quill-menu__sub-content)
- .quill-combobox__item:not([data-action]) {
+ .quill-combobox__content .quill-combobox__item:not([data-action]) {
/* Button's row padding and row icon size, then the item's gap. */
padding-inline-start: calc(0.5rem + 0.875rem + var(--quill-combobox-item-gap));
}
diff --git a/packages/quill/packages/primitives/src/combobox.tsx b/packages/quill/packages/primitives/src/combobox.tsx
index 70ca430dcb1a..bb56489c0a88 100644
--- a/packages/quill/packages/primitives/src/combobox.tsx
+++ b/packages/quill/packages/primitives/src/combobox.tsx
@@ -27,8 +27,6 @@ function Combobox<Value, Multiple extends boolean | undefined = false>({
)
}
-const useComboboxFilteredItems = ComboboxPrimitive.useFilteredItems
-
function ComboboxValue({ ...props }: ComboboxPrimitive.Value.Props): React.ReactElement {
return <ComboboxPrimitive.Value data-slot="combobox-value" {...props} />
}
@@ -357,7 +355,6 @@ function useComboboxAnchor(): React.RefObject<HTMLDivElement> {
}
export {
- useComboboxFilteredItems,
Combobox,
ComboboxInput,
ComboboxContent,
diff --git a/packages/quill/packages/primitives/src/dropdown-menu.stories.tsx b/packages/quill/packages/primitives/src/dropdown-menu.stories.tsx
index 8e114fe4a5b7..d56974997087 100644
--- a/packages/quill/packages/primitives/src/dropdown-menu.stories.tsx
+++ b/packages/quill/packages/primitives/src/dropdown-menu.stories.tsx
@@ -1,5 +1,6 @@
import type { Meta, StoryObj } from '@storybook/react'
import { Copy, ExpandIcon, Folder, MoreVertical, Pencil, TrashIcon } from 'lucide-react'
+import * as React from 'react'
import { useState } from 'react'
import { Button } from './button'
@@ -7,6 +8,10 @@ import {
DropdownMenu,
DropdownMenuGroup,
DropdownMenuContent,
+ DropdownMenuEmpty,
+ DropdownMenuFilterProvider,
+ DropdownMenuInput,
+ DropdownMenuList,
DropdownMenuTrigger,
DropdownMenuItem,
DropdownMenuSelectAll,
@@ -155,6 +160,49 @@ export const Checkboxes: Story = {
},
} satisfies Story
+function FilterableMenu({
+ trigger,
+ placeholder,
+ searchLabel = placeholder,
+ emptyText,
+ modal,
+ autoFocus,
+ children,
+}: {
+ trigger: React.ReactNode
+ placeholder: string
+ searchLabel?: string
+ emptyText: string
+ modal?: boolean
+ autoFocus?: boolean
+ children: React.ReactNode
+}): React.ReactElement {
+ const [open, setOpen] = useState(true)
+ return (
+ <DropdownMenuFilterProvider autoHighlight>
+ <DropdownMenu modal={modal} open={open} onOpenChange={setOpen}>
+ <DropdownMenuTrigger render={<Button variant="outline" size="sm" />}>{trigger}</DropdownMenuTrigger>
+ <DropdownMenuContent className="w-64" flush>
+ <DropdownMenuInput autoFocus={autoFocus} placeholder={placeholder} aria-label={searchLabel} />
+ <DropdownMenuEmpty>{emptyText}</DropdownMenuEmpty>
+ <DropdownMenuList>{children}</DropdownMenuList>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ </DropdownMenuFilterProvider>
+ )
+}
+
+export const Filterable: Story = {
+ render: () => (
+ <FilterableMenu trigger="Click me" placeholder="Search projects" emptyText="No project matches" autoFocus>
+ <DropdownMenuItem>Analytics</DropdownMenuItem>
+ <DropdownMenuItem>Billing</DropdownMenuItem>
+ <DropdownMenuItem>Marketing site</DropdownMenuItem>
+ <DropdownMenuItem>Onboarding</DropdownMenuItem>
+ </FilterableMenu>
+ ),
+} satisfies Story
+
export const DescriptionsAndDisabledReasons: Story = {
render: () => (
<DropdownMenu defaultOpen>
@@ -396,15 +444,64 @@ export const Overflow: Story = {
{timezone ?? 'Pick a timezone'}
</DropdownMenuTrigger>
<DropdownMenuContent className="w-auto min-w-56">
- <DropdownMenuRadioGroup value={timezone} onValueChange={setTimezone}>
+ {TIMEZONES.map((tz) => (
+ <DropdownMenuItem key={tz} onClick={() => setTimezone(tz)}>
+ {tz}
+ </DropdownMenuItem>
+ ))}
+ </DropdownMenuContent>
+ </DropdownMenu>
+ )
+ },
+} satisfies Story
+
+export const OverflowAndFiltering: Story = {
+ render: () => {
+ const [timezone, setTimezone] = useState<string | undefined>(undefined)
+ const [timezones, setTimezones] = useState<string[]>([])
+ return (
+ <div className="flex gap-4">
+ <div className="w-64">
+ <FilterableMenu
+ trigger={timezone ?? 'Pick a timezone'}
+ placeholder="Search timezones"
+ emptyText="No timezone matches"
+ modal={false}
+ >
+ <DropdownMenuRadioGroup value={timezone} onValueChange={setTimezone}>
+ {TIMEZONES.map((tz) => (
+ <DropdownMenuRadioItem key={tz} value={tz}>
+ {tz}
+ </DropdownMenuRadioItem>
+ ))}
+ </DropdownMenuRadioGroup>
+ </FilterableMenu>
+ </div>
+ <div className="w-64">
+ <FilterableMenu
+ trigger={timezones.length > 0 ? `${timezones.length} timezones` : 'Pick timezones'}
+ placeholder="Search timezones"
+ searchLabel="Search several timezones"
+ emptyText="No timezone matches"
+ modal={false}
+ >
{TIMEZONES.map((tz) => (
- <DropdownMenuRadioItem key={tz} value={tz}>
+ <DropdownMenuCheckboxItem
+ key={tz}
+ checked={timezones.includes(tz)}
+ closeOnClick={false}
+ onCheckedChange={(checked) =>
+ setTimezones((current) =>
+ checked ? [...current, tz] : current.filter((item) => item !== tz)
+ )
+ }
+ >
{tz}
- </DropdownMenuRadioItem>
+ </DropdownMenuCheckboxItem>
))}
- </DropdownMenuRadioGroup>
- </DropdownMenuContent>
- </DropdownMenu>
+ </FilterableMenu>
+ </div>
+ </div>
)
},
} satisfies Story
diff --git a/packages/quill/packages/primitives/src/dropdown-menu.tsx b/packages/quill/packages/primitives/src/dropdown-menu.tsx
index b61c1f462ceb..ae52bcb132db 100644
--- a/packages/quill/packages/primitives/src/dropdown-menu.tsx
+++ b/packages/quill/packages/primitives/src/dropdown-menu.tsx
@@ -6,9 +6,11 @@ import * as React from 'react'
import { Button } from './button'
import { Checkbox } from './checkbox'
+import { InputGroup, InputGroupInput } from './input-group'
import { Kbd } from './kbd'
import { cn } from './lib/utils'
import { MenuItemBody } from './menu-item-body'
+import { MenuEmpty } from './menu-empty'
import { MenuLabel } from './menu-label'
import { RadioIndicator } from './radio-group'
import { hasTooltipContent, withTooltip } from './with-tooltip'
@@ -213,6 +215,40 @@ const DropdownMenuSubContent = React.forwardRef<
)
})
+const DropdownMenuFilterProvider = MenuPrimitive.FilterProvider
+
+const DropdownMenuInput = React.forwardRef<HTMLInputElement, MenuPrimitive.Input.Props>(
+ function DropdownMenuInput(props, ref) {
+ return (
+ <div className="quill-menu__input" data-slot="dropdown-menu-input">
+ <InputGroup>
+ <MenuPrimitive.Input ref={ref} render={<InputGroupInput />} {...props} />
+ </InputGroup>
+ </div>
+ )
+ }
+)
+
+const DropdownMenuEmpty = React.forwardRef<HTMLDivElement, MenuPrimitive.Empty.Props>(
+ function DropdownMenuEmpty(props, ref) {
+ return <MenuPrimitive.Empty ref={ref} data-slot="dropdown-menu-empty" render={<MenuEmpty />} {...props} />
+ }
+)
+
+const DropdownMenuList = React.forwardRef<HTMLDivElement, MenuPrimitive.List.Props>(function DropdownMenuList(
+ { className, ...props },
+ ref
+) {
+ return (
+ <MenuPrimitive.List
+ ref={ref}
+ data-slot="dropdown-menu-list"
+ className={cn('quill-menu__list', className)}
+ {...props}
+ />
+ )
+})
+
const DropdownMenuCheckboxItem = React.forwardRef<
React.ComponentRef<typeof MenuPrimitive.CheckboxItem>,
MenuPrimitive.CheckboxItem.Props &
@@ -454,7 +490,11 @@ export {
DropdownMenuPortal,
DropdownMenuTrigger,
DropdownMenuContent,
+ DropdownMenuEmpty,
+ DropdownMenuFilterProvider,
DropdownMenuGroup,
+ DropdownMenuInput,
+ DropdownMenuList,
DropdownMenuLabel,
DropdownMenuItem,
DropdownMenuCheckboxItem,
diff --git a/packages/quill/packages/primitives/src/index.ts b/packages/quill/packages/primitives/src/index.ts
index ec358f7be31a..9ef1dbe2e74f 100644
--- a/packages/quill/packages/primitives/src/index.ts
+++ b/packages/quill/packages/primitives/src/index.ts
@@ -125,7 +125,6 @@ export {
ComboboxTrigger,
ComboboxValue,
useComboboxAnchor,
- useComboboxFilteredItems,
} from './combobox'
export {
ContextMenu,
@@ -177,7 +176,11 @@ export {
DropdownMenuPortal,
DropdownMenuTrigger,
DropdownMenuContent,
+ DropdownMenuEmpty,
+ DropdownMenuFilterProvider,
DropdownMenuGroup,
+ DropdownMenuInput,
+ DropdownMenuList,
DropdownMenuLabel,
DropdownMenuItem,
DropdownMenuCheckboxItem,
diff --git a/packages/quill/packages/primitives/src/menu.css b/packages/quill/packages/primitives/src/menu.css
index 765a7d8f754a..cb0a4b27f76d 100644
--- a/packages/quill/packages/primitives/src/menu.css
+++ b/packages/quill/packages/primitives/src/menu.css
@@ -61,10 +61,28 @@
}
.quill-menu__content[data-flush] .quill-menu__scroller {
+ display: flex;
+ flex-direction: column;
+ max-height: min(calc(var(--spacing, 0.25rem) * 72), var(--available-height));
padding: 0;
overflow: hidden;
}
+ .quill-menu__input {
+ flex-shrink: 0;
+ padding: 0.25rem;
+ border-bottom: 1px solid var(--border);
+ }
+
+ .quill-menu__list {
+ flex: 1;
+ min-height: 0;
+ padding: 0.25rem;
+ overflow-y: auto;
+ overscroll-behavior: contain;
+ scroll-padding-block: 0.25rem;
+ }
+
.quill-menu__content[data-closed] .quill-menu__scroller,
.quill-menu__sub-content[data-closed] .quill-menu__scroller {
overflow: hidden;
@@ -135,7 +153,12 @@
}
/* A leading avatar in a menu row takes the row's icon size, so avatars and icons line up down the menu. */
- :is([data-slot='dropdown-menu-item'], [data-slot='dropdown-menu-sub-trigger'], .quill-menu-item__title)
+ :is(
+ [data-slot='dropdown-menu-item'],
+ [data-slot='dropdown-menu-checkbox-item'],
+ [data-slot='dropdown-menu-sub-trigger'],
+ .quill-menu-item__title
+ )
> [data-slot='avatar'][data-size] {
--avatar-size: 0.875rem;
diff --git a/packages/quill/packages/quill/package.json b/packages/quill/packages/quill/package.json
index 3a8de7283513..b84fdf04cf0e 100644
--- a/packages/quill/packages/quill/package.json
+++ b/packages/quill/packages/quill/package.json
@@ -62,7 +62,7 @@
"vite-plugin-dts": "^4.5.4"
},
"peerDependencies": {
- "@base-ui/react": "^1.4.0",
+ "@base-ui/react": "^1.9.0",
"react": "^18.3.1 || ^19.0.0",
"react-dom": "^18.3.1 || ^19.0.0",
"tailwindcss": "^4.0.0"