Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
feat(dify-ui): add the filterable DropdownMenu parts (#43775)
yyh71f5875e1b09
diff --git a/packages/dify-ui/docs/overlays.md b/packages/dify-ui/docs/overlays.mdindex 836c1652766..60066f19f73 100644--- a/packages/dify-ui/docs/overlays.md+++ b/packages/dify-ui/docs/overlays.md@@ -64,6 +64,8 @@ Toast remains one layer above ordinary overlays.- Use `AlertDialog` only for a destructive or must-confirm decision requiring an explicit answer.- Use `Drawer` for side-panel interactions that follow the drawer model.- Use `DropdownMenu` for button-triggered action lists and `ContextMenu` for context actions.+ A long action list filters with `DropdownMenuFilterProvider`; choosing a value is+ [`Combobox`] in [Selection].- Use [`Tooltip`] for a supplementary visual label on a control that already has a primaryaction and an accessible name. Use `Infotip` when the information icon's action is to openthe explanation. Text length alone does not determine the component. Follow the@@ -80,6 +82,8 @@ spacing unless its API documents a measured exception.[Base UI Portal]: https://base-ui.com/react/overview/quick-start#portals[Infotip contract]: ../src/infotip/README.md[MDN `isolation`]: https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/isolation+[Selection]: selection.md+[`Combobox`]: https://base-ui.com/react/components/combobox[`Dialog.Portal`]: https://base-ui.com/react/components/dialog#portal[`Popover`]: https://base-ui.com/react/components/popover[`PreviewCard`]: https://base-ui.com/react/components/preview-carddiff --git a/packages/dify-ui/docs/styling.md b/packages/dify-ui/docs/styling.mdindex 9e704eb24ce..bdd60f0130f 100644--- a/packages/dify-ui/docs/styling.md+++ b/packages/dify-ui/docs/styling.md@@ -74,7 +74,10 @@ share one ring. Rows inside a composite defer to its highlight. Parts that onlyText controls (Input, Textarea, InputGroup, NumberField, and the Combobox and Autocomplete inputgroups) draw that ring on the visible field. It replaces the hover border, and an invalid fieldkeeps its border and fill inside it. Switch, Checkbox, and Radio leave a gap between the control and-the indicator, because their checked fill is the indicator color.+the indicator, because their checked fill is the indicator color. `DropdownMenuInputGroup` is the+exception: Base UI marks `Menu.Input` with `data-highlighted` while the input holds the keyboard+highlight, so the group draws the ring on that state and drops it once the arrow keys move the+highlight into the list.Attach the indicator to the element that visually represents focus. If a visible wrapper containsthe native focus target, select that descendant state from the wrapper; for example, `SliderThumb`diff --git a/packages/dify-ui/src/combobox/index.tsx b/packages/dify-ui/src/combobox/index.tsxindex cb699ca3510..b151223a27e 100644--- a/packages/dify-ui/src/combobox/index.tsx+++ b/packages/dify-ui/src/combobox/index.tsx@@ -112,7 +112,8 @@ const comboboxInputGroupVariants = cva([textControlGroupClassName,'group/combobox items-center',- // Inside the popup the group is the search box: it lines up with the options on 4px gutters,+ // Inside the popup the group is the search box, laid out like `DropdownMenuInputGroup`: it+ // lines up with the options on 4px gutters,// hosts an inline icon, and takes over the horizontal padding from its input and controls.// The popup marks itself with a data attribute because a `role="dialog"` ancestor could also be// a Dialog hosting a field anchor.@@ -212,6 +213,7 @@ const comboboxControlVariants = cva(type ComboboxClearProps = BaseCombobox.Clear.Props & VariantProps<typeof comboboxControlVariants>+// Same look as `DropdownMenuClear`; change both together.function ComboboxClear({className,children,@@ -406,6 +408,7 @@ function ComboboxSeparator({ className, ...props }: ComboboxSeparatorProps) {type ComboboxEmptyProps = BaseCombobox.Empty.Props+// Same look as `DropdownMenuEmpty`; change both together.function ComboboxEmpty({ className, ...props }: ComboboxEmptyProps) {return (<BaseCombobox.Emptydiff --git a/packages/dify-ui/src/context-menu/__tests__/index.spec.tsx b/packages/dify-ui/src/context-menu/__tests__/index.spec.tsxindex ffd75a8f42d..d97c63064f9 100644--- a/packages/dify-ui/src/context-menu/__tests__/index.spec.tsx+++ b/packages/dify-ui/src/context-menu/__tests__/index.spec.tsx@@ -71,7 +71,7 @@ describe('context-menu wrapper', () => {})describe('ContextMenuSubContent', () => {- it('should position sub-content at right-start with default placement when props are omitted', async () => {+ it('should place sub-content inline-end-start when placement is omitted', async () => {const screen = await renderWithSafeViewport(<ContextMenu open><ContextMenuTrigger aria-label="context trigger">Open</ContextMenuTrigger>@@ -86,12 +86,19 @@ describe('context-menu wrapper', () => {</ContextMenu>,)+ const submenu = screen.getByRole('menu', { name: 'More actions' })+ const submenuTrigger = screen.getByRole('menuitem', { name: 'More actions' })++ await expect.element(submenu).toHaveAttribute('data-side', 'inline-end')+ await expect.element(submenu).toHaveAttribute('data-align', 'start')+ // Left-to-right, so the submenu sits to the right of its trigger.await expect- .element(screen.getByRole('menu', { name: 'More actions' }))- .toHaveAttribute('data-side', 'right')- await expect- .element(screen.getByRole('menu', { name: 'More actions' }))- .toHaveAttribute('data-align', 'start')+ .poll(+ () =>+ submenu.element().getBoundingClientRect().left >=+ submenuTrigger.element().getBoundingClientRect().right - 1,+ )+ .toBe(true)await expect.element(screen.getByRole('menuitem', { name: 'Sub action' })).toBeInTheDocument()})})diff --git a/packages/dify-ui/src/context-menu/index.tsx b/packages/dify-ui/src/context-menu/index.tsxindex 6912391d562..8aa9ead7237 100644--- a/packages/dify-ui/src/context-menu/index.tsx+++ b/packages/dify-ui/src/context-menu/index.tsx@@ -217,9 +217,10 @@ function ContextMenuSubTrigger({type ContextMenuSubContentProps = ContextMenuContentProps+// Base UI's own submenu default: it opens away from the trigger and follows the text direction.function ContextMenuSubContent({children,- placement = 'right-start',+ placement = 'inline-end-start',sideOffset = 4,alignOffset = 0,className,diff --git a/packages/dify-ui/src/dropdown-menu/__tests__/index.spec.tsx b/packages/dify-ui/src/dropdown-menu/__tests__/index.spec.tsxindex 2e4864a0d8b..7676f5cafaa 100644--- a/packages/dify-ui/src/dropdown-menu/__tests__/index.spec.tsx+++ b/packages/dify-ui/src/dropdown-menu/__tests__/index.spec.tsx@@ -1,10 +1,17 @@import type * as React from 'react'+import { page, userEvent } from 'vite-plus/test/browser'import { render } from 'vitest-browser-react'import {DropdownMenu,+ DropdownMenuClear,DropdownMenuContent,+ DropdownMenuEmpty,+ DropdownMenuFilterProvider,+ DropdownMenuInput,+ DropdownMenuInputGroup,DropdownMenuItem,DropdownMenuLinkItem,+ DropdownMenuList,DropdownMenuPopup,DropdownMenuPortal,DropdownMenuPositioner,@@ -18,7 +25,120 @@ import {const renderWithSafeViewport = (ui: React.ReactNode) =>render(<div style={{ minHeight: '100vh', minWidth: '100vw', padding: '240px' }}>{ui}</div>)+function FilterableMenu({ items = ['Rename workspace', 'Manage billing'] }: { items?: string[] }) {+ return (+ <DropdownMenuFilterProvider>+ <DropdownMenu open>+ <DropdownMenuTrigger>Workspace actions</DropdownMenuTrigger>+ <DropdownMenuContent>+ <DropdownMenuInputGroup>+ <span aria-hidden="true" data-testid="search-icon">+ 🔍+ </span>+ <DropdownMenuInput aria-label="Filter actions" />+ <DropdownMenuClear data-testid="clear" />+ </DropdownMenuInputGroup>+ <DropdownMenuEmpty>No actions match</DropdownMenuEmpty>+ <DropdownMenuList>+ {items.map((item) => (+ <DropdownMenuItem key={item}>{item}</DropdownMenuItem>+ ))}+ </DropdownMenuList>+ </DropdownMenuContent>+ </DropdownMenu>+ </DropdownMenuFilterProvider>+ )+}+describe('dropdown-menu wrapper', () => {+ describe('filtering', () => {+ it('should focus the filter input when the input group surface is pressed', async () => {+ const screen = await renderWithSafeViewport(<FilterableMenu />)+ const input = screen.getByRole('searchbox', { name: 'Filter actions' })++ await expect.element(input).toHaveFocus()+ ;(input.element() as HTMLInputElement).blur()+ await expect.element(input).not.toHaveFocus()++ await userEvent.click(screen.getByTestId('search-icon'))++ await expect.element(input).toHaveFocus()+ })++ it('should draw the input ring from the highlighted state instead of focus', async () => {+ const screen = await renderWithSafeViewport(<FilterableMenu />)+ const input = screen.getByRole('searchbox', { name: 'Filter actions' })+ // A ring is a box shadow with a spread; the group's shadow stays spread-free while unringed.+ const ringSpread = () =>+ /0px 0px 0px 2px/.test(getComputedStyle(input.element().parentElement!).boxShadow)++ await expect.element(input).toHaveFocus()+ // Base UI owns when the input is highlighted; this checks what the group draws for each state.+ input.element().removeAttribute('data-highlighted')+ await expect.poll(ringSpread).toBe(false)++ input.element().setAttribute('data-highlighted', '')+ await expect.poll(ringSpread).toBe(true)+ })++ it('should keep the input in view when the available height is smaller than the list', async () => {+ const originalViewport = { height: window.innerHeight, width: window.innerWidth }+ await page.viewport(800, 260)++ try {+ const screen = await render(+ <FilterableMenu+ items={Array.from({ length: 30 }, (_, index) => `Action ${index + 1}`)}+ />,+ )+ const popup = screen.getByRole('dialog')+ const list = screen.getByRole('menu')+ const input = screen.getByRole('searchbox', { name: 'Filter actions' })++ await expect.element(input).toHaveFocus()+ await userEvent.keyboard('{ArrowDown}'.repeat(30))+ await expect+ .element(screen.getByRole('menuitem', { name: 'Action 30' }))+ .toHaveAttribute('data-highlighted')++ await expect+ .poll(() => popup.element().scrollHeight <= popup.element().clientHeight)+ .toBe(true)+ await expect+ .poll(() => list.element().scrollHeight > list.element().clientHeight)+ .toBe(true)+ await expect+ .poll(() => {+ const popupRect = popup.element().getBoundingClientRect()+ const inputRect = input.element().getBoundingClientRect()+ return inputRect.top >= popupRect.top && inputRect.bottom <= popupRect.bottom+ })+ .toBe(true)+ } finally {+ await page.viewport(originalViewport.width, originalViewport.height)+ }+ })++ it('should reset the query from the clear control and keep focus in the input', async () => {+ const screen = await renderWithSafeViewport(<FilterableMenu />)+ const input = screen.getByRole('searchbox', { name: 'Filter actions' })++ await userEvent.fill(input, 'bill')+ await expect.element(screen.getByRole('menuitem', { name: 'Manage billing' })).toBeVisible()+ await expect+ .element(screen.getByRole('menuitem', { name: 'Rename workspace' }))+ .not.toBeInTheDocument()++ await userEvent.click(screen.getByTestId('clear'))++ await expect.element(input).toHaveValue('')+ await expect.element(input).toHaveFocus()+ await expect+ .element(screen.getByRole('menuitem', { name: 'Rename workspace' }))+ .toBeInTheDocument()+ })+ })+describe('DropdownMenuContent', () => {it('should position content at bottom-end with default placement when props are omitted', async () => {const screen = await renderWithSafeViewport(@@ -96,7 +216,7 @@ describe('dropdown-menu wrapper', () => {})describe('DropdownMenuSubContent', () => {- it('should position sub-content at left-start with default placement when props are omitted', async () => {+ it('should place sub-content inline-end-start when placement is omitted', async () => {const screen = await renderWithSafeViewport(<DropdownMenu open><DropdownMenuTrigger aria-label="menu trigger">Open</DropdownMenuTrigger>@@ -111,12 +231,19 @@ describe('dropdown-menu wrapper', () => {</DropdownMenu>,)+ const submenu = screen.getByRole('menu', { name: 'More actions' })+ const submenuTrigger = screen.getByRole('menuitem', { name: 'More actions' })++ await expect.element(submenu).toHaveAttribute('data-side', 'inline-end')+ await expect.element(submenu).toHaveAttribute('data-align', 'start')+ // Left-to-right, so the submenu sits to the right of its trigger.await expect- .element(screen.getByRole('menu', { name: 'More actions' }))- .toHaveAttribute('data-side', 'left')- await expect- .element(screen.getByRole('menu', { name: 'More actions' }))- .toHaveAttribute('data-align', 'start')+ .poll(+ () =>+ submenu.element().getBoundingClientRect().left >=+ submenuTrigger.element().getBoundingClientRect().right - 1,+ )+ .toBe(true)await expect.element(screen.getByRole('menuitem', { name: 'Sub action' })).toBeInTheDocument()})diff --git a/packages/dify-ui/src/dropdown-menu/index.stories.tsx b/packages/dify-ui/src/dropdown-menu/index.stories.tsxindex 5053a84e00f..e42555366cd 100644--- a/packages/dify-ui/src/dropdown-menu/index.stories.tsx+++ b/packages/dify-ui/src/dropdown-menu/index.stories.tsx@@ -6,11 +6,17 @@ import {DropdownMenu,DropdownMenuCheckboxItem,DropdownMenuCheckboxItemIndicator,+ DropdownMenuClear,DropdownMenuContent,+ DropdownMenuEmpty,+ DropdownMenuFilterProvider,DropdownMenuGroup,DropdownMenuGroupLabel,+ DropdownMenuInput,+ DropdownMenuInputGroup,DropdownMenuItem,DropdownMenuLinkItem,+ DropdownMenuList,DropdownMenuRadioGroup,DropdownMenuRadioItem,DropdownMenuRadioItemIndicator,@@ -44,7 +50,7 @@ const meta = {docs: {description: {component:- 'Compound dropdown menu built on Base UI Menu. Supports items, separators, group labels, submenus, radio groups, checkbox items, destructive items, and disabled states.',+ 'Compound dropdown menu built on Base UI Menu. Supports items, separators, group labels, submenus, radio groups, checkbox items, destructive items, disabled states, and filtering. Filtering is a Base UI preview feature: wrap `DropdownMenu` in `DropdownMenuFilterProvider`, place `DropdownMenuInput` in a `DropdownMenuInputGroup` inside the content, and put the items in `DropdownMenuList`. The popup then becomes a dialog that holds the searchbox and the menu.',},},},@@ -402,3 +408,215 @@ export const DetachedTrigger: Story = {})},}++const filterableActionGroups = [+ {+ label: 'Workspace',+ actions: ['Rename workspace', 'Invite members', 'Manage billing'],+ },+ {+ label: 'Danger zone',+ actions: ['Archive workspace', 'Delete workspace'],+ },+]++const moveTargets = ['Personal space', 'Team space', 'Archive']+const shareTargets = ['Design team', 'Engineering team', 'Everyone']++function FilterableDemo() {+ const [lastAction, setLastAction] = React.useState<string | null>(null)++ return (+ <div className="flex flex-col items-start gap-3">+ <DropdownMenuFilterProvider>+ <DropdownMenu>+ <TriggerButton label="Workspace actions" />+ <DropdownMenuContent className="w-64">+ <DropdownMenuInputGroup>+ <span+ aria-hidden+ className="i-ri-search-line size-4 shrink-0 text-components-input-text-placeholder"+ />+ <DropdownMenuInput aria-label="Filter actions" placeholder="Filter actions…" />+ <DropdownMenuClear />+ </DropdownMenuInputGroup>+ <DropdownMenuEmpty>No actions match</DropdownMenuEmpty>+ <DropdownMenuList>+ {filterableActionGroups.map((group, index) => (+ <DropdownMenuGroup key={group.label}>+ {index > 0 && <DropdownMenuSeparator />}+ <DropdownMenuGroupLabel>{group.label}</DropdownMenuGroupLabel>+ {group.actions.map((action) => (+ <DropdownMenuItem+ key={action}+ variant={group.label === 'Danger zone' ? 'destructive' : 'default'}+ onClick={() => setLastAction(action)}+ >+ {action}+ </DropdownMenuItem>+ ))}+ {index === 0 && (+ <React.Fragment>+ {/* A submenu without its own provider stays unfiltered. */}+ <DropdownMenuSub>+ <DropdownMenuSubTrigger>Move to</DropdownMenuSubTrigger>+ <DropdownMenuSubContent>+ <DropdownMenuList>+ {moveTargets.map((target) => (+ <DropdownMenuItem+ key={target}+ onClick={() => setLastAction(`Move to ${target}`)}+ >+ {target}+ </DropdownMenuItem>+ ))}+ </DropdownMenuList>+ </DropdownMenuSubContent>+ </DropdownMenuSub>+ {/* A submenu wrapped in its own provider filters with its own input. */}+ <DropdownMenuFilterProvider>+ <DropdownMenuSub>+ <DropdownMenuSubTrigger>Share with</DropdownMenuSubTrigger>+ <DropdownMenuSubContent>+ <DropdownMenuInputGroup>+ <span+ aria-hidden+ className="i-ri-search-line size-4 shrink-0 text-components-input-text-placeholder"+ />+ <DropdownMenuInput+ aria-label="Filter teams"+ placeholder="Filter teams…"+ />+ <DropdownMenuClear />+ </DropdownMenuInputGroup>+ <DropdownMenuEmpty>No teams match</DropdownMenuEmpty>+ <DropdownMenuList>+ {shareTargets.map((target) => (+ <DropdownMenuItem+ key={target}+ onClick={() => setLastAction(`Share with ${target}`)}+ >+ {target}+ </DropdownMenuItem>+ ))}+ </DropdownMenuList>+ </DropdownMenuSubContent>+ </DropdownMenuSub>+ </DropdownMenuFilterProvider>+ </React.Fragment>+ )}+ </DropdownMenuGroup>+ ))}+ </DropdownMenuList>+ </DropdownMenuContent>+ </DropdownMenu>+ </DropdownMenuFilterProvider>+ <p role="status" aria-label="Last action" className="system-xs-regular text-text-tertiary">+ {lastAction ?? 'No action yet'}+ </p>+ </div>+ )+}++export const Filterable: Story = {+ parameters: {+ docs: {+ story: { autoplay: false },+ description: {+ story:+ 'Filtering is a Base UI preview feature. Opening with a click or the keyboard focuses the input; opening on hover does not, so the on-screen keyboard stays hidden. Arrow keys move the highlight while the input keeps focus, Enter runs the highlighted action, Tab closes the menu, and Shift+Tab returns focus to the trigger. Groups without matches hide, and the empty state announces when nothing matches. Place the separator between groups inside the later group so it hides with the groups before it. A submenu trigger matches like an item; a submenu stays unfiltered unless its `DropdownMenuSub` is wrapped in its own `DropdownMenuFilterProvider` with its own input, as "Share with" is. The right arrow opens a submenu and focuses its input when it has one, the left arrow closes it from an empty input and returns focus to the parent input, and each level keeps its own query. Pass `autoHighlight` to highlight the first match while typing.',+ },+ },+ },+ render: () => <FilterableDemo />,+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement)+ const body = within(canvasElement.ownerDocument.body)+ const trigger = canvas.getByRole('button', { name: 'Workspace actions' })++ await userEvent.click(trigger)+ const input = await body.findByRole('searchbox', { name: 'Filter actions' })+ await waitFor(async () => {+ await expect(input).toHaveFocus()+ })+ await expect(body.getByRole('menuitem', { name: 'Manage billing' })).toBeInTheDocument()++ await userEvent.type(input, 'billing')+ await expect(body.getByRole('menuitem', { name: 'Manage billing' })).toBeInTheDocument()+ await expect(body.queryByRole('menuitem', { name: 'Rename workspace' })).not.toBeInTheDocument()+ await expect(body.queryByText('Danger zone')).not.toBeVisible()++ await userEvent.keyboard('{ArrowDown}')+ await expect(body.getByRole('menuitem', { name: 'Manage billing' })).toHaveAttribute(+ 'data-highlighted',+ )+ await expect(input).toHaveFocus()+ await expect(input).not.toHaveAttribute('data-highlighted')++ await userEvent.clear(input)+ await userEvent.type(input, 'archive')+ await expect(body.getByRole('menuitem', { name: 'Archive workspace' })).toBeInTheDocument()+ await expect(body.queryByText('Workspace')).not.toBeVisible()+ for (const separator of body.queryAllByRole('separator', { hidden: true })) {+ await expect(separator).not.toBeVisible()+ }++ // An unfiltered submenu opens from the parent query and closes back into it.+ await userEvent.clear(input)+ await userEvent.type(input, 'move')+ await expect(body.getByRole('menuitem', { name: 'Move to' })).toBeInTheDocument()+ await userEvent.keyboard('{ArrowDown}{ArrowRight}')+ await expect(await body.findByRole('menuitem', { name: 'Team space' })).toBeInTheDocument()+ await userEvent.keyboard('{ArrowLeft}')+ await waitFor(async () => {+ await expect(body.queryByRole('menuitem', { name: 'Team space' })).not.toBeInTheDocument()+ })++ // A filterable submenu focuses its own input and keeps its own query.+ await userEvent.clear(input)+ await userEvent.type(input, 'share')+ await userEvent.keyboard('{ArrowDown}{ArrowRight}')+ const submenuInput = await body.findByRole('searchbox', { name: 'Filter teams' })+ await waitFor(async () => {+ await expect(submenuInput).toHaveFocus()+ })+ // The left arrow closes the submenu only from an empty input; with text it moves the caret.+ await userEvent.keyboard('{ArrowLeft}')+ await waitFor(async () => {+ await expect(body.queryByRole('searchbox', { name: 'Filter teams' })).not.toBeInTheDocument()+ })+ await waitFor(async () => {+ await expect(input).toHaveFocus()+ })+ await expect(input).toHaveValue('share')+ await userEvent.keyboard('{ArrowRight}')+ await userEvent.type(await body.findByRole('searchbox', { name: 'Filter teams' }), 'eng')+ await expect(body.getByRole('menuitem', { name: 'Engineering team' })).toBeInTheDocument()+ await expect(body.queryByRole('menuitem', { name: 'Everyone' })).not.toBeInTheDocument()+ await userEvent.keyboard('{ArrowDown}{Enter}')+ await expect(canvas.getByRole('status', { name: 'Last action' })).toHaveTextContent(+ 'Share with Engineering team',+ )+ await expect(trigger).toHaveAttribute('aria-expanded', 'false')++ await userEvent.click(trigger)+ const reopenedInput = await body.findByRole('searchbox', { name: 'Filter actions' })+ await userEvent.type(reopenedInput, 'zzz')+ await expect(await body.findByText('No actions match')).toHaveAttribute('role', 'status')++ await userEvent.clear(reopenedInput)+ await userEvent.type(reopenedInput, 'rename')+ await userEvent.keyboard('{ArrowDown}{Enter}')+ await expect(canvas.getByRole('status', { name: 'Last action' })).toHaveTextContent(+ 'Rename workspace',+ )++ await userEvent.click(trigger)+ await body.findByRole('searchbox', { name: 'Filter actions' })+ await userEvent.keyboard('{Shift>}{Tab}{/Shift}')+ await waitFor(async () => {+ await expect(trigger).toHaveFocus()+ })+ await expect(trigger).toHaveAttribute('aria-expanded', 'false')+ },+}diff --git a/packages/dify-ui/src/dropdown-menu/index.tsx b/packages/dify-ui/src/dropdown-menu/index.tsxindex 9a8447a526a..9621266402d 100644--- a/packages/dify-ui/src/dropdown-menu/index.tsx+++ b/packages/dify-ui/src/dropdown-menu/index.tsx@@ -1,10 +1,13 @@'use client'import type * as React from 'react'+import type { InputGroupProps } from '../input-group'import type { MenuItemVariant } from '../overlay-shared'import type { Placement } from '../placement'import { Menu } from '@base-ui/react/menu'import { cn } from '../cn'+import { textControlGroupInputClassName } from '../form-control-shared'+import { InputGroup } from '../input-group'import { resolveClassName } from '../internals/resolve-class-name'import {floatingGroupLabelClassName,@@ -25,6 +28,11 @@ const DropdownMenuSub = Menu.SubmenuRootconst DropdownMenuGroup = Menu.Groupconst createDropdownMenuHandle = Menu.createHandle+// A filterable menu hosts its input in `DropdownMenuInputGroup` and its items in `DropdownMenuList`,+// so the list owns the `menu` role and the scrolling while the popup keeps its padding.+const DropdownMenuFilterProvider = Menu.FilterProvider+const useDropdownMenuFilter = Menu.useFilter+type DropdownMenuHandle<Payload = unknown> = Menu.Handle<Payload>type DropdownMenuActions = Menu.Root.Actions@@ -46,6 +54,97 @@ function DropdownMenuTrigger<Payload = unknown>({type DropdownMenuPortalProps = Menu.Portal.Propstype DropdownMenuSubProps = Menu.SubmenuRoot.Propstype DropdownMenuGroupProps = Menu.Group.Props+type DropdownMenuFilterProviderProps = Menu.FilterProvider.Props++type DropdownMenuInputGroupProps = InputGroupProps++// A dify-ui composition over `InputGroup` with the menu's input and clear parts; it carries no Base+// UI state attributes. Laid out like the Combobox popup search, with a minimum width because the+// input has no intrinsic width and a menu popup is sized by its items. `InputGroup` owns the focus+// ring; this group withholds it while the focused input lacks Base UI's `data-highlighted`, so the+// ring shows while the input holds the keyboard highlight and gives way to the item highlight once+// the arrow keys move into the list.+function DropdownMenuInputGroup({ className, ...props }: DropdownMenuInputGroupProps) {+ return (+ <InputGroup+ className={cn(+ 'mx-1 mb-1 w-auto min-w-48 gap-0.5 px-2 has-[>input:focus:not([data-highlighted])]:ring-0',+ className,+ )}+ {...props}+ />+ )+}++type DropdownMenuInputProps = Menu.Input.Props++// The group's padding and icon surround the input, so it keeps only a narrow inset.+function DropdownMenuInput({ className, ...props }: DropdownMenuInputProps) {+ return (+ <Menu.Input+ className={(state) =>+ cn(textControlGroupInputClassName, 'px-1', resolveClassName(className, state))+ }+ {...props}+ />+ )+}++type DropdownMenuClearProps = Menu.Clear.Props++// Base UI shows it only while the input has a value and keeps it out of the accessibility tree and+// the tab order. Same look as `ComboboxClear`; change both together.+function DropdownMenuClear({ className, children, ...props }: DropdownMenuClearProps) {+ return (+ <Menu.Clear+ className={(state) =>+ cn(+ 'flex size-5 shrink-0 items-center justify-center rounded-md text-text-tertiary outline-hidden hover:bg-components-input-bg-hover hover:text-text-secondary',+ resolveClassName(className, state),+ )+ }+ {...props}+ >+ {children ?? <span className="i-ri-close-line size-4" aria-hidden="true" />}+ </Menu.Clear>+ )+}++type DropdownMenuEmptyProps = Menu.Empty.Props++// Same look as `ComboboxEmpty`; change both together.+function DropdownMenuEmpty({ className, ...props }: DropdownMenuEmptyProps) {+ return (+ <Menu.Empty+ className={(state) =>+ cn('px-3 py-2 system-sm-regular text-text-tertiary', resolveClassName(className, state))+ }+ {...props}+ />+ )+}++type DropdownMenuListProps = Menu.List.Props++// The popup keeps its vertical padding and the items keep their inset, so the list adds none.+// Filtering hides a group whose items all match out, so a separator between groups goes at the+// start of the later group and shows only while a visible group precedes it. Every separator+// directly inside a group follows that rule, so separate items with groups, not with a separator+// among them. A separator placed directly in the list is not managed.+function DropdownMenuList({ className, ...props }: DropdownMenuListProps) {+ return (+ <Menu.List+ className={(state) =>+ cn(+ 'max-h-80 min-h-0 overflow-x-hidden overflow-y-auto overscroll-contain outline-hidden',+ '[&>:not([hidden])~[role=group]:not([hidden])>[role=separator]]:block [&>[role=group]>[role=separator]]:hidden',+ resolveClassName(className, state),+ )+ }+ {...props}+ />+ )+}type DropdownMenuRadioGroupProps<Value = unknown> = Omit<Menu.RadioGroup.Props,'defaultValue' | 'onValueChange' | 'value'@@ -133,12 +232,12 @@ function DropdownMenuGroupLabel({ className, ...props }: DropdownMenuGroupLabelP}type DropdownMenuPositionerProps = Omit<Menu.Positioner.Props, 'side' | 'align'> & {- placement?: Placement+ placement: Placement}function DropdownMenuPositioner({className,- placement = 'bottom-end',+ placement,sideOffset = 4,alignOffset = 0,...props@@ -159,12 +258,15 @@ function DropdownMenuPositioner({type DropdownMenuPopupProps = Menu.Popup.Props+// When a `DropdownMenuList` is rendered, Base UI hands the `menu` role to it and the popup becomes a+// column that never scrolls itself, so the list scrolls and anything else in the popup stays put.function DropdownMenuPopup({ className, ...props }: DropdownMenuPopupProps) {return (<Menu.PopupclassName={(state) =>cn(menuPopupBaseClassName,+ 'not-[[role=menu]]:flex not-[[role=menu]]:flex-col not-[[role=menu]]:overflow-hidden',floatingPopupAnimationClassName,resolveClassName(className, state),)@@ -175,8 +277,9 @@ function DropdownMenuPopup({ className, ...props }: DropdownMenuPopupProps) {}type DropdownMenuContentProps = Omit<DropdownMenuPopupProps, 'children'> &- Pick<DropdownMenuPositionerProps, 'alignOffset' | 'placement' | 'sideOffset'> & {+ Pick<DropdownMenuPositionerProps, 'alignOffset' | 'sideOffset'> & {children: React.ReactNode+ placement?: Placement}function DropdownMenuContent({@@ -234,9 +337,10 @@ function DropdownMenuSubTrigger({type DropdownMenuSubContentProps = DropdownMenuContentProps+// Base UI's own submenu default: it opens away from the trigger and follows the text direction.function DropdownMenuSubContent({children,- placement = 'left-start',+ placement = 'inline-end-start',sideOffset = 4,alignOffset = 0,className,@@ -314,11 +418,17 @@ export {DropdownMenu,DropdownMenuCheckboxItem,DropdownMenuCheckboxItemIndicator,+ DropdownMenuClear,DropdownMenuContent,+ DropdownMenuEmpty,+ DropdownMenuFilterProvider,DropdownMenuGroup,DropdownMenuGroupLabel,+ DropdownMenuInput,+ DropdownMenuInputGroup,DropdownMenuItem,DropdownMenuLinkItem,+ DropdownMenuList,DropdownMenuPopup,DropdownMenuPortal,DropdownMenuPositioner,@@ -330,18 +440,25 @@ export {DropdownMenuSubContent,DropdownMenuSubTrigger,DropdownMenuTrigger,+ useDropdownMenuFilter,}export type {DropdownMenuActions,DropdownMenuCheckboxItemIndicatorProps,DropdownMenuCheckboxItemProps,+ DropdownMenuClearProps,DropdownMenuContentProps,+ DropdownMenuEmptyProps,+ DropdownMenuFilterProviderProps,DropdownMenuGroupLabelProps,DropdownMenuGroupProps,DropdownMenuHandle,+ DropdownMenuInputGroupProps,+ DropdownMenuInputProps,DropdownMenuItemProps,DropdownMenuLinkItemProps,+ DropdownMenuListProps,DropdownMenuPopupProps,DropdownMenuPortalProps,DropdownMenuPositionerProps,diff --git a/packages/dify-ui/src/form-control-shared.ts b/packages/dify-ui/src/form-control-shared.tsindex a0f40f04e4a..e79cb3c4650 100644--- a/packages/dify-ui/src/form-control-shared.ts+++ b/packages/dify-ui/src/form-control-shared.ts@@ -35,3 +35,12 @@ export const textControlGroupClassName = ['data-disabled:hover:border-transparent data-disabled:hover:bg-components-input-bg-disabled','motion-reduce:transition-none',]++// The input inside `textControlGroupClassName`: the group owns the surface, so the input is bare.+// Its horizontal padding belongs to the layout around it.+export const textControlGroupInputClassName = [+ 'w-0 min-w-0 flex-1 appearance-none rounded-none border-0 bg-transparent py-1.75 system-sm-regular text-components-input-text-filled caret-primary-600 outline-hidden',+ 'placeholder:text-components-input-text-placeholder',+ 'read-only:cursor-default',+ 'disabled:cursor-not-allowed disabled:text-components-input-text-filled-disabled',+]diff --git a/packages/dify-ui/src/input-group/README.md b/packages/dify-ui/src/input-group/README.mdindex 284b4f6818b..cf00767311d 100644--- a/packages/dify-ui/src/input-group/README.md+++ b/packages/dify-ui/src/input-group/README.md@@ -8,7 +8,9 @@ pointer surface without changing the input's native semantics.## Anatomy-Compose exactly one direct `InputGroupInput` and one or more direct `InputGroupAddon` children:+Compose exactly one direct input with the content that shares its surface, usually one or more+direct `InputGroupAddon` children. The input is `InputGroupInput`, or another native input that owns+its own value and states:```tsx<InputGroup>@@ -21,8 +23,8 @@ Compose exactly one direct `InputGroupInput` and one or more direct `InputGroupA`InputGroupInput` owns the native input and its value. Addons own layout and supporting content.Do not absolutely position content over a standalone `Input` to recreate this shared surface.-Place `InputGroupInput` before every addon in the DOM. The input is the primary control and addons-are read or reached after it. Use `align="inline-start"` or `align="inline-end"` for visual+Place the input before every addon in the DOM. The input is the primary control and addons are+read or reached after it; only decorative `aria-hidden` content may come first. Use `align="inline-start"` or `align="inline-end"` for visualplacement without changing semantic or focus order.## Accessibility and interactiondiff --git a/packages/dify-ui/src/input-group/index.tsx b/packages/dify-ui/src/input-group/index.tsxindex 20bbbb7aeed..d125f4cb507 100644--- a/packages/dify-ui/src/input-group/index.tsx+++ b/packages/dify-ui/src/input-group/index.tsx@@ -6,6 +6,7 @@ import type * as React from 'react'import { Input as BaseInput } from '@base-ui/react/input'import { cva } from 'class-variance-authority'import { cn } from '../cn'+import { textControlGroupInputClassName } from '../form-control-shared'import { resolveClassName } from '../internals/resolve-class-name'const interactiveElementSelector =@@ -62,15 +63,7 @@ function InputGroupInput({ className, ...props }: InputGroupInputProps) {<BaseInput{...props}className={(state) =>- cn(- [- 'w-0 min-w-0 flex-1 appearance-none rounded-none border-0 bg-transparent px-3 py-1.75 system-sm-regular text-components-input-text-filled caret-primary-600 outline-hidden',- 'placeholder:text-components-input-text-placeholder',- 'read-only:cursor-default',- 'disabled:cursor-not-allowed disabled:text-components-input-text-filled-disabled',- ],- resolveClassName(className, state),- )+ cn(textControlGroupInputClassName, 'px-3', resolveClassName(className, state))}/>)diff --git a/packages/dify-ui/src/placement.ts b/packages/dify-ui/src/placement.tsindex 63196e036b1..561ab8653d3 100644--- a/packages/dify-ui/src/placement.ts+++ b/packages/dify-ui/src/placement.ts@@ -1,8 +1,8 @@-// Placement type for overlay positioning.-// Mirrors the Floating UI Placement spec — a stable set of 12 CSS-based position values.-// Reference: https://floating-ui.com/docs/useFloating#placement+// Base UI positions a popup with `side` and `align`; a placement joins the two in Floating UI's+// `side-align` notation, with the `center` alignment left off. The inline sides follow the text+// direction, so `inline-end` is right in LTR and left in RTL.-type Side = 'top' | 'bottom' | 'left' | 'right'+type Side = 'top' | 'bottom' | 'left' | 'right' | 'inline-start' | 'inline-end'type Align = 'start' | 'center' | 'end'export type Placement =@@ -18,6 +18,12 @@ export type Placement =| 'left'| 'left-start'| 'left-end'+ | 'inline-start'+ | 'inline-start-start'+ | 'inline-start-end'+ | 'inline-end'+ | 'inline-end-start'+ | 'inline-end-end'const PLACEMENT_PARTS = {top: { side: 'top', align: 'center' },@@ -32,6 +38,12 @@ const PLACEMENT_PARTS = {left: { side: 'left', align: 'center' },'left-start': { side: 'left', align: 'start' },'left-end': { side: 'left', align: 'end' },+ 'inline-start': { side: 'inline-start', align: 'center' },+ 'inline-start-start': { side: 'inline-start', align: 'start' },+ 'inline-start-end': { side: 'inline-start', align: 'end' },+ 'inline-end': { side: 'inline-end', align: 'center' },+ 'inline-end-start': { side: 'inline-end', align: 'start' },+ 'inline-end-end': { side: 'inline-end', align: 'end' },} satisfies Record<Placement, { side: Side; align: Align }>export function parsePlacement(placement: Placement): { side: Side; align: Align } {diff --git a/packages/dify-ui/src/popover/index.stories.tsx b/packages/dify-ui/src/popover/index.stories.tsxindex 1ea37addfc0..c06069908d5 100644--- a/packages/dify-ui/src/popover/index.stories.tsx+++ b/packages/dify-ui/src/popover/index.stories.tsx@@ -206,6 +206,12 @@ const PLACEMENTS: PopoverPlacement[] = ['left-start','left','left-end',+ 'inline-start-start',+ 'inline-start',+ 'inline-start-end',+ 'inline-end-start',+ 'inline-end',+ 'inline-end-end',]function PlacementsDemo() {diff --git a/packages/dify-ui/src/preview-card/index.stories.tsx b/packages/dify-ui/src/preview-card/index.stories.tsxindex 946b2470cc4..dde91c11927 100644--- a/packages/dify-ui/src/preview-card/index.stories.tsx+++ b/packages/dify-ui/src/preview-card/index.stories.tsx@@ -124,6 +124,12 @@ const PLACEMENTS: PreviewCardPlacement[] = ['left-start','left','left-end',+ 'inline-start-start',+ 'inline-start',+ 'inline-start-end',+ 'inline-end-start',+ 'inline-end',+ 'inline-end-end',]function PlacementsDemo() {diff --git a/packages/dify-ui/src/tooltip/index.stories.tsx b/packages/dify-ui/src/tooltip/index.stories.tsxindex 4110f068439..ec27c474d97 100644--- a/packages/dify-ui/src/tooltip/index.stories.tsx+++ b/packages/dify-ui/src/tooltip/index.stories.tsx@@ -104,6 +104,12 @@ const PLACEMENTS: TooltipPlacement[] = ['left-start','left','left-end',+ 'inline-start-start',+ 'inline-start',+ 'inline-start-end',+ 'inline-end-start',+ 'inline-end',+ 'inline-end-end',]function PlacementsDemo() {