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
fix(ui): trap focus within date and time pickers (#44772)
yyh853ca772c59b
diff --git a/packages/dify-ui/src/date-time/README.md b/packages/dify-ui/src/date-time/README.mdindex ad1c7abd67b..d55a52ae0cf 100644--- a/packages/dify-ui/src/date-time/README.md+++ b/packages/dify-ui/src/date-time/README.md@@ -1,6 +1,6 @@# Date and time pickers-These three families share field anatomy, a non-modal popover and keyboard navigation. Choose+These three families share field anatomy, a focus-trapped popover and keyboard navigation. Choosefrom the value's meaning; they do not accept free-form text or arbitrary collection values.| Public subpath | Value / `onValueChange` | Native form value | Selection commits |@@ -94,10 +94,11 @@ Unchanged values do not emit duplicate callbacks. Open/close events remain Popovsuccessful confirmation, Clear or reset closes through its `imperative-action` mechanism.Time and date-time edits, including Now, stay in the open session until OK. Switching date/time-views preserves the draft. Dismissal discards it; reopening starts from the committed value.-Changing the controlled value or time zone starts a fresh draft. Unchanged confirmation does not-emit a duplicate value change. In DatePicker, a day selection commits immediately. The month/year-selector only changes the displayed month when confirmed; it does not select a date.+views preserves the draft. Close, Escape and outside press discard it; reopening starts from the+committed value. Changing the controlled value or time zone starts a fresh draft. Unchanged+confirmation does not emit a duplicate value change. In DatePicker, a day selection commits+immediately. The month/year selector only changes the displayed month when confirmed; it does not+select a date.The calendar uses DayPicker's grid navigation. Adjacent-month dates remain selectable and, whilethe popup remains open, switch the view to their month. `minDate`, `maxDate` and@@ -110,8 +111,12 @@ Selection follows focus within the draft, not the committed field value:- Up/Down move one option; Page Up/Down move five; Home/End reach the endpoints. Navigation clampsat the ends; no `loopFocus` API is exposed.- Numeric locating accepts ASCII and localized digits. Month names also support typeahead.-- Tab moves between columns and actions, not every option. Escape leaves month/year selection- first; Escape from the main picker dismisses and restores trigger focus. Tab can leave the popup.+- Tab moves between columns and actions, not every option. Tab and Shift+Tab wrap within the+ popup, keeping the selection session active until confirmation or dismissal. A visually hidden Close+ button lets screen-reader users dismiss the entire picker without adding a Tab stop. Cancel and+ Escape in month/year selection discard those edits and return to the calendar; Escape from the+ main picker dismisses. Keyboard dismissal restores trigger focus; outside press keeps+ focus on the clicked focusable control. The popup does not lock page scrolling.- Hover does not select. Keyboard changes scroll immediately; pointer selection may scrollsmoothly, respecting reduced motion. Wheel/touch scrolling updates the draft and aligns thenearest option at the top when it settles.diff --git a/packages/dify-ui/src/date-time/__tests__/field.spec.tsx b/packages/dify-ui/src/date-time/__tests__/field.spec.tsxindex 190e909fa2f..e556e6dc3f1 100644--- a/packages/dify-ui/src/date-time/__tests__/field.spec.tsx+++ b/packages/dify-ui/src/date-time/__tests__/field.spec.tsx@@ -478,9 +478,33 @@ it('validates on leaving the complete picker, not when focus enters its portalle.getByRole('listbox', { name: 'Hour' }).getByRole('option', { name: '2', exact: true }).click()+ let restoreFocus: FrameRequestCallback | undefined+ const animationFrame = vi+ .spyOn(window, 'requestAnimationFrame')+ .mockImplementationOnce((callback) => {+ restoreFocus = callback+ return 0+ })+ try {+ await userEvent.tab({ shift: true })+ // Let blur timers run while the browser is waiting to render the focus-restoration frame.+ await new Promise((resolve) => setTimeout(resolve, 0))+ expect(restoreFocus).toBeDefined()+ expect(validate).not.toHaveBeenCalled()+ expect(stateOf(screen)).toMatchObject({ touched: false, focused: true })+ } finally {+ animationFrame.mockRestore()+ restoreFocus?.(performance.now())+ }+ await expect.element(screen.getByRole('button', { name: 'OK', exact: true })).toHaveFocus()+ await userEvent.tab()+ await expect+ .element(screen.getByRole('listbox', { name: 'Hour' }).getByRole('option', { name: '2' }))+ .toHaveFocus()expect(validate).not.toHaveBeenCalled()expect(stateOf(screen)).toMatchObject({ dirty: false, touched: false, focused: true })- await screen.getByRole('button', { name: 'Next field' }).click()+ await screen.getByText('Next field', { exact: true }).click()+ await expect.element(screen.getByRole('button', { name: 'Next field' })).toHaveFocus()expect(validate).toHaveBeenCalledExactlyOnceWith('13:30', { departure: '13:30' })await expect.element(screen.getByText('Choose another time.', { exact: true })).toBeVisible()const trigger = screen.getByRole('button', { name: /^Departure / })@@ -857,7 +881,7 @@ it('keeps Clear inside the field focus boundary while dismissing an open popup',</Form>,)await screen.getByRole('button', { name: /^Departure / }).click()- await screen.getByRole('button', { name: 'Clear departure' }).click()+ await screen.getByLabelText('Clear departure', { exact: true }).click()await expect.element(screen.getByRole('button', { name: 'Departure', exact: true })).toHaveFocus()expect(validate).not.toHaveBeenCalled()expect(stateOf(screen)).toMatchObject({ touched: false, focused: true, filled: false })diff --git a/packages/dify-ui/src/date-time/__tests__/focus.spec.tsx b/packages/dify-ui/src/date-time/__tests__/focus.spec.tsxnew file mode 100644index 00000000000..f5d6941ce37--- /dev/null+++ b/packages/dify-ui/src/date-time/__tests__/focus.spec.tsx@@ -0,0 +1,169 @@+import { userEvent } from 'vite-plus/test/browser'+import { render } from 'vitest-browser-react'+import { DatePicker, DatePickerContent, DatePickerLabel, DatePickerTrigger } from '../date-picker'+import {+ DateTimePicker,+ DateTimePickerContent,+ DateTimePickerLabel,+ DateTimePickerTrigger,+} from '../date-time-picker'+import { TimePicker, TimePickerContent, TimePickerLabel, TimePickerTrigger } from '../time-picker'++type Kind = 'date' | 'time' | 'date-time'++function Example({ kind, onChange }: { kind: Kind; onChange: () => void }) {+ return (+ <div style={{ display: 'flex', alignItems: 'start', gap: 32 }}>+ <button type="button">Before picker</button>+ {kind === 'date' ? (+ <DatePicker defaultValue="2025-01-15" onValueChange={onChange}>+ <DatePickerLabel>Selection</DatePickerLabel>+ <DatePickerTrigger />+ <DatePickerContent />+ </DatePicker>+ ) : kind === 'time' ? (+ <TimePicker defaultValue="13:30" onValueChange={onChange}>+ <TimePickerLabel>Selection</TimePickerLabel>+ <TimePickerTrigger />+ <TimePickerContent />+ </TimePicker>+ ) : (+ <DateTimePicker+ timeZone="UTC"+ defaultValue={new Date('2025-01-15T13:30:00Z')}+ onValueChange={onChange}+ >+ <DateTimePickerLabel>Selection</DateTimePickerLabel>+ <DateTimePickerTrigger />+ <DateTimePickerContent />+ </DateTimePicker>+ )}+ <button type="button">After picker</button>+ </div>+ )+}++it.each(['date', 'time', 'date-time'] as const)(+ '%s keeps keyboard navigation inside the selection session until explicitly closed',+ async (kind) => {+ const changed = vi.fn()+ const screen = await render(<Example kind={kind} onChange={changed} />)+ await screen.getByRole('button', { name: 'Before picker' }).click()+ await userEvent.tab()+ const trigger = screen.getByRole('button', { name: /^Selection / })+ await expect.element(trigger).toHaveFocus()+ await userEvent.keyboard('{Enter}')+ const selected =+ kind === 'time'+ ? screen.getByRole('listbox', { name: 'Hour' }).getByRole('option', { name: '1' })+ : screen.getByRole('button', { name: /Wednesday, January 15th, 2025/ })+ await expect.element(selected).toHaveFocus()+ const first =+ kind === 'time'+ ? selected+ : screen.getByRole('button', { name: 'Choose month and year: January 2025' })+ for (let index = 0; index < (kind === 'time' ? 0 : 3); index++) {+ await userEvent.tab({ shift: true })+ }+ await expect.element(first).toHaveFocus()+ await userEvent.tab({ shift: true })+ const last = kind === 'date' ? selected : screen.getByRole('button', { name: 'OK' })+ await expect.element(last).toHaveFocus()+ await userEvent.tab()+ await expect.element(first).toHaveFocus()+ await expect+ .element(screen.getByRole('dialog', { name: 'Selection', exact: true }))+ .toBeVisible()+ expect(changed).not.toHaveBeenCalled()+ const close = screen.getByRole('button', { name: 'Close', exact: true })+ await expect.element(close).toHaveAttribute('tabindex', '-1')+ expect(close.element().getBoundingClientRect().width).toBeLessThanOrEqual(1)+ expect(close.element().getBoundingClientRect().height).toBeLessThanOrEqual(1)+ // Assistive technologies activate this visually hidden control without pointer hit testing.+ const closeButton = close.element() as HTMLButtonElement+ closeButton.click()+ await expect.element(screen.getByRole('dialog')).not.toBeInTheDocument()+ await expect.element(trigger).toHaveFocus()+ await userEvent.tab()+ await expect.element(screen.getByRole('button', { name: 'After picker' })).toHaveFocus()+ expect(changed).not.toHaveBeenCalled()+ },+)++it.each(['time', 'date-time'] as const)(+ '%s discards time edits through Close and outside press while preserving the clicked focus target',+ async (kind) => {+ const changed = vi.fn()+ const screen = await render(<Example kind={kind} onChange={changed} />)+ const trigger = screen.getByRole('button', { name: /^Selection / })+ for (const dismissal of ['close', 'outside'] as const) {+ await trigger.click()+ if (kind === 'date-time') {+ await screen.getByRole('button', { name: 'Pick Time: 1:30 PM' }).click()+ }+ const hours = screen.getByRole('listbox', { name: 'Hour' })+ await expect.element(hours.getByRole('option', { name: '1' })).toHaveFocus()+ await userEvent.keyboard('{ArrowDown}')+ await expect.element(hours.getByRole('option', { name: '2' })).toHaveFocus()+ if (dismissal === 'close') {+ const closeButton = screen+ .getByRole('button', { name: 'Close', exact: true })+ .element() as HTMLButtonElement+ closeButton.click()+ await expect.element(trigger).toHaveFocus()+ } else {+ await screen.getByText('After picker', { exact: true }).click()+ await expect.element(screen.getByRole('button', { name: 'After picker' })).toHaveFocus()+ }+ await expect.element(screen.getByRole('dialog')).not.toBeInTheDocument()+ expect(changed).not.toHaveBeenCalled()+ }+ await trigger.click()+ if (kind === 'date-time') {+ await screen.getByRole('button', { name: 'Pick Time: 1:30 PM' }).click()+ }+ await expect+ .element(screen.getByRole('listbox', { name: 'Hour' }).getByRole('option', { name: '1' }))+ .toHaveFocus()+ },+)++it.each(['date', 'date-time'] as const)(+ '%s traps focus in month/year selection and Close dismisses the entire picker',+ async (kind) => {+ const changed = vi.fn()+ const screen = await render(<Example kind={kind} onChange={changed} />)+ const trigger = screen.getByRole('button', { name: /^Selection / })+ await trigger.click()+ const monthTrigger = screen.getByRole('button', { name: 'Choose month and year: January 2025' })+ await monthTrigger.click()+ const january = screen.getByRole('option', { name: 'January', exact: true })+ await expect.element(january).toHaveFocus()+ await userEvent.keyboard('{ArrowDown}')+ await expect+ .element(screen.getByRole('option', { name: 'February', exact: true }))+ .toHaveFocus()+ await userEvent.tab({ shift: true })+ await expect.element(monthTrigger).toHaveFocus()+ await userEvent.tab({ shift: true })+ await expect.element(screen.getByRole('button', { name: 'OK', exact: true })).toHaveFocus()+ await userEvent.tab()+ await expect.element(monthTrigger).toHaveFocus()+ const closeButton = screen+ .getByRole('button', { name: 'Close', exact: true })+ .element() as HTMLButtonElement+ closeButton.click()+ await expect.element(screen.getByRole('dialog')).not.toBeInTheDocument()+ await expect.element(trigger).toHaveFocus()+ expect(changed).not.toHaveBeenCalled()+ await trigger.click()+ await monthTrigger.click()+ await expect.element(january).toHaveFocus()+ await userEvent.keyboard('{Escape}')+ await expect.element(monthTrigger).toHaveFocus()+ await expect.element(screen.getByRole('grid')).toBeVisible()+ await userEvent.keyboard('{Escape}')+ await expect.element(screen.getByRole('dialog')).not.toBeInTheDocument()+ await expect.element(trigger).toHaveFocus()+ },+)diff --git a/packages/dify-ui/src/date-time/date-picker/index.tsx b/packages/dify-ui/src/date-time/date-picker/index.tsxindex 1c0e919bbd8..08c636412c2 100644--- a/packages/dify-ui/src/date-time/date-picker/index.tsx+++ b/packages/dify-ui/src/date-time/date-picker/index.tsx@@ -29,6 +29,8 @@ import {} from '../internal/picker-parts'import { usePickerValue } from '../internal/use-picker-value'+type DatePickerLabels = CalendarPanelLabels & { close: string }+type DatePickerChangeEventReason = PickerChangeEventReasontype DatePickerChangeEventDetails = PickerChangeEventDetails@@ -39,12 +41,13 @@ type DatePickerProps = PickerFieldProps &defaultValue?: string | null/** Called on day confirmation, clearing or form reset. */onValueChange?: (value: string | null, details: DatePickerChangeEventDetails) => void- labels?: Partial<CalendarPanelLabels>+ labels?: Partial<DatePickerLabels>}type ContextValue = Omit<DatePickerProps,- 'value' | 'defaultValue' | 'onValueChange' | 'children'+ 'value' | 'defaultValue' | 'onValueChange' | 'children' | 'labels'> & {+ labels: DatePickerLabelsvalue: Exclude<DatePickerProps['value'], undefined>commit: (value: string | null, details: DatePickerChangeEventDetails) => boolean}@@ -54,13 +57,14 @@ function useContext() {if (!context) throw new Error('DatePicker parts require DatePicker.')return context}-const defaultLabels: CalendarPanelLabels = {+const defaultLabels: DatePickerLabels = {previousMonth: 'Previous month',nextMonth: 'Next month',chooseMonthAndYear: 'Choose month and year',month: 'Month',year: 'Year',cancel: 'Cancel',+ close: 'Close',apply: 'OK',unavailable: 'This date is unavailable.',}@@ -92,16 +96,14 @@ function DatePicker({props.isDateUnavailable?.(value)),)+ const labels = { ...defaultLabels, ...props.labels }+return (- <Context.Provider value={{ ...props, value, commit }}>+ <Context.Provider value={{ ...props, value, commit, labels }}><PickerRoot{...props}invalid={props.invalid || unavailable}- validationMessage={- unavailable- ? (props.labels?.unavailable ?? defaultLabels.unavailable)- : props.validationMessage- }+ validationMessage={unavailable ? labels.unavailable : props.validationMessage}placeholder={props.placeholder ?? 'Select date'}displayValue={parsedValue@@ -134,9 +136,9 @@ const DatePickerClear = PickerClearconst DatePickerLabel = PickerLabelconst DatePickerValue = PickerValuefunction DatePickerContent(props: DatePickerContentProps) {- const { value } = useContext()+ const { value, labels } = useContext()return (- <PickerContent {...props}>+ <PickerContent {...props} closeLabel={labels.close}><Session key={value ?? ''} /></PickerContent>)@@ -166,7 +168,7 @@ function Session() {minDate={minDate}maxDate={maxDate}isDateUnavailable={isDateUnavailable}- labels={{ ...defaultLabels, ...labels }}+ labels={labels}/>)}diff --git a/packages/dify-ui/src/date-time/date-time-picker/index.tsx b/packages/dify-ui/src/date-time/date-time-picker/index.tsxindex c38c131e79d..da891add18c 100644--- a/packages/dify-ui/src/date-time/date-time-picker/index.tsx+++ b/packages/dify-ui/src/date-time/date-time-picker/index.tsx@@ -36,7 +36,7 @@ import { usePickerValue } from '../internal/use-picker-value'import { getZonedWallTime, resolveZonedWallTime } from './zoned-value'type DateTimePickerLabels = CalendarPanelLabels &- TimePanelLabels & { pickTime: string; backToDate: string; now: string }+ TimePanelLabels & { close: string; pickTime: string; backToDate: string; now: string }type DateTimePickerChangeEventReason = PickerChangeEventReasontype DateTimePickerChangeEventDetails = PickerChangeEventDetails@@ -54,8 +54,9 @@ type DateTimePickerProps = PickerFieldProps &}type ContextValue = Omit<DateTimePickerProps,- 'value' | 'defaultValue' | 'onValueChange' | 'children'+ 'value' | 'defaultValue' | 'onValueChange' | 'children' | 'labels'> & {+ labels: DateTimePickerLabelsvalue: Exclude<DateTimePickerProps['value'], undefined>commit: (value: Date | null, details: DateTimePickerChangeEventDetails) => boolean}@@ -72,6 +73,7 @@ const defaultLabels: DateTimePickerLabels = {month: 'Month',year: 'Year',cancel: 'Cancel',+ close: 'Close',apply: 'OK',hour: 'Hour',minute: 'Minute',@@ -113,16 +115,14 @@ function DateTimePicker({props.isTimeUnavailable?.(wall)),)+ const labels = { ...defaultLabels, ...props.labels }+return (- <Context.Provider value={{ ...props, value, commit }}>+ <Context.Provider value={{ ...props, value, commit, labels }}><PickerRoot{...props}invalid={props.invalid || unavailable}- validationMessage={- unavailable- ? (props.labels?.unavailable ?? defaultLabels.unavailable)- : props.validationMessage- }+ validationMessage={unavailable ? labels.unavailable : props.validationMessage}placeholder={props.placeholder ?? 'Select date and time'}displayValue={value@@ -158,9 +158,9 @@ const DateTimePickerClear = PickerClearconst DateTimePickerLabel = PickerLabelconst DateTimePickerValue = PickerValuefunction DateTimePickerContent(props: DateTimePickerContentProps) {- const { value, timeZone } = useContext()+ const { value, timeZone, labels } = useContext()return (- <PickerContent {...props}>+ <PickerContent {...props} closeLabel={labels.close}><Session key={`${value?.getTime() ?? ''}-${timeZone}`} /></PickerContent>)@@ -185,7 +185,6 @@ function Session() {)const [view, setView] = React.useState<'date' | 'time'>('date')const ref = React.useRef<HTMLDivElement>(null)- const text = { ...defaultLabels, ...labels }function availableInstant(candidate: typeof draft) {const instant = resolveZonedWallTime(candidate, timeZone, value)if (@@ -249,7 +248,7 @@ function Session() {close()}}>- {text.apply}+ {labels.apply}</Button>)return (@@ -265,14 +264,14 @@ function Session() {minDate={minDate}maxDate={maxDate}isDateUnavailable={isDateUnavailable}- labels={text}+ labels={labels}footer={<React.Fragment><Buttonsize="small"variant="secondary-accent"className="gap-1 px-1.5"- aria-label={`${text.pickTime}: ${timeText}`}+ aria-label={`${labels.pickTime}: ${timeText}`}onClick={() => changeView('time')}><span@@ -283,7 +282,7 @@ function Session() {</Button><div className="flex gap-1"><Button size="small" variant="ghost-accent" onClick={setNow}>- {text.now}+ {labels.now}</Button>{apply}</div>@@ -292,7 +291,7 @@ function Session() {/>) : (<PickerPanel- header={<PickerPanelHeader>{text.pickTime}</PickerPanelHeader>}+ header={<PickerPanelHeader>{labels.pickTime}</PickerPanelHeader>}footer={<React.Fragment><Button@@ -305,11 +304,11 @@ function Session() {aria-hidden="true"className="i-ri-calendar-line size-3 forced-colors:text-[ButtonText] forced-colors:forced-color-adjust-none"/>- {text.backToDate}+ {labels.backToDate}</Button><div className="flex gap-1"><Button size="small" variant="ghost-accent" onClick={setNow}>- {text.now}+ {labels.now}</Button>{apply}</div>@@ -322,7 +321,7 @@ function Session() {onValueChange={(update) =>setDraft((previous) => ({ ...previous, time: update(previous.time) }))}- labels={text}+ labels={labels}locale={locale.code}hourCycle={hourCycle}/>@@ -334,7 +333,7 @@ function Session() {role="status"className="shrink-0 px-2 system-xs-regular text-text-destructive">- {text.unavailable}+ {labels.unavailable}</p>)}</div>diff --git a/packages/dify-ui/src/date-time/internal/picker-parts.tsx b/packages/dify-ui/src/date-time/internal/picker-parts.tsxindex a8fd75885cb..aa196368e58 100644--- a/packages/dify-ui/src/date-time/internal/picker-parts.tsx+++ b/packages/dify-ui/src/date-time/internal/picker-parts.tsx@@ -38,7 +38,7 @@ import { IconButton } from '../../icon-button'import { formLabelClassName } from '../../internal/form-control'import { resolveClassName } from '../../internal/resolve-class-name'import { mergeProps } from '../../merge-props'-import { Popover, PopoverContent, PopoverTrigger } from '../../popover'+import { Popover, PopoverClose, PopoverContent, PopoverTrigger } from '../../popover'import { useMergedRefs } from '../../use-merged-refs'import { arePickerValuesEqual } from './use-picker-value'@@ -206,7 +206,9 @@ function PickerRoot({field.validation.change(value, resetVersion !== handledResetVersionRef.current)})+ const blurTimeout = useTimeout()const focus = useStableCallback((element: HTMLElement) => {+ blurTimeout.clear()if (disabled || element.matches(':disabled')) returnfocusedPartRef.current = elementfield.focusOwnerRef.current = triggerRef@@ -223,13 +225,25 @@ function PickerRoot({if (contains(triggerRef.current, nextTarget) ||contains(clearRef.current, nextTarget) ||- contains(popupRef.current, nextTarget)+ contains(popupRef.current, nextTarget) ||+ (nextTarget?.hasAttribute('data-base-ui-focus-guard') &&+ nextTarget.parentElement === popupRef.current?.parentElement))returnif (field.focusOwnerRef.current !== triggerRef) return- releaseFocus()- field.setTouched(true)- if (field.validationMode === 'onBlur') field.validation.commit(value)+ // Closing popovers can briefly restore trigger focus before the outside target receives it.+ blurTimeout.start(0, () => {+ const target = activeElement(ownerDocument(inputRef.current))+ if (+ contains(triggerRef.current, target) ||+ contains(clearRef.current, target) ||+ contains(popupRef.current, target)+ )+ return+ releaseFocus()+ field.setTouched(true)+ if (field.validationMode === 'onBlur') field.validation.commit(value)+ })})React.useLayoutEffect(() => {if (disabled || inputRef.current?.matches(':disabled')) releaseFocus()@@ -348,6 +362,7 @@ function PickerRoot({}}/><Popover+ modal="trap-focus"open={props.open}defaultOpen={props.defaultOpen}onOpenChange={(open, details) => {@@ -607,12 +622,13 @@ function PickerClear({ onClick, disabled, ref, ...props }: PickerClearProps) {type PickerContentProps = Omit<PopoverContentProps, 'children' | 'initialFocus' | 'render'>function PickerContent({children,+ closeLabel,ref,className,'aria-label': ariaLabel,'aria-labelledby': ariaLabelledBy,...props-}: PickerContentProps & { children: React.ReactNode }) {+}: PickerContentProps & { children: React.ReactNode; closeLabel: string }) {const { labelId, popupRef, focus, blur } = usePickerContext()const focusRef = usePickerFocusRef(popupRef)const mergedRef = useMergedRefs(popupRef, ref, focusRef)@@ -644,7 +660,18 @@ function PickerContent({popupRef.current?.querySelector<HTMLElement>('button:not(:disabled)') ??true}- render={(popupProps, state) => <div {...popupProps}>{state.open ? children : null}</div>}+ render={(popupProps, state) => (+ <div {...popupProps}>+ {state.open && (+ <React.Fragment>+ {children}+ <PopoverClose style={visuallyHidden} tabIndex={-1}>+ {closeLabel}+ </PopoverClose>+ </React.Fragment>+ )}+ </div>+ )}>{children}</PopoverContent>diff --git a/packages/dify-ui/src/date-time/time-picker/__tests__/index.spec.tsx b/packages/dify-ui/src/date-time/time-picker/__tests__/index.spec.tsxindex 920513e0c40..a5d3189047c 100644--- a/packages/dify-ui/src/date-time/time-picker/__tests__/index.spec.tsx+++ b/packages/dify-ui/src/date-time/time-picker/__tests__/index.spec.tsx@@ -201,7 +201,7 @@ it('keeps a quarter-hour field reachable and rounds Now down to its current intevi.restoreAllMocks()})-it('discards a draft when Tab leaves the nonmodal picker inside a modal dialog', async () => {+it('traps focus in a nested picker and discards its draft without closing the parent dialog', async () => {const changed = vi.fn()const screen = await render(<Dialog defaultOpen>@@ -225,7 +225,13 @@ it('discards a draft when Tab leaves the nonmodal picker inside a modal dialog',await userEvent.tab()await expect.element(screen.getByRole('button', { name: 'OK', exact: true })).toHaveFocus()await userEvent.tab()- await expect.element(screen.getByRole('button', { name: 'Save settings' })).toHaveFocus()+ await expect+ .element(screen.getByRole('listbox', { name: 'Hour' }).getByRole('option', { name: '2' }))+ .toHaveFocus()+ await userEvent.tab({ shift: true })+ await expect.element(screen.getByRole('button', { name: 'OK', exact: true })).toHaveFocus()+ await userEvent.keyboard('{Escape}')+ await expect.element(screen.getByRole('button', { name: 'Time 1:30 PM' })).toHaveFocus()await expect.element(screen.getByRole('dialog', { name: 'Time', exact: true })).not.toBeInTheDocument()@@ -233,6 +239,16 @@ it('discards a draft when Tab leaves the nonmodal picker inside a modal dialog',.element(screen.getByRole('dialog', { name: 'Settings', exact: true })).toBeInTheDocument()expect(changed).not.toHaveBeenCalled()+ await screen.getByRole('button', { name: 'Time 1:30 PM' }).click()+ await expect+ .element(screen.getByRole('listbox', { name: 'Hour' }).getByRole('option', { name: '1' }))+ .toHaveFocus()+ const closeButton = screen+ .getByRole('button', { name: 'Close', exact: true })+ .element() as HTMLButtonElement+ closeButton.click()+ await expect.element(screen.getByRole('button', { name: 'Time 1:30 PM' })).toHaveFocus()+ await expect.element(screen.getByRole('dialog', { name: 'Settings', exact: true })).toBeVisible()})it('aligns pointer selections and immediately positions keyboard selections at the same top anchor', async () => {diff --git a/packages/dify-ui/src/date-time/time-picker/index.tsx b/packages/dify-ui/src/date-time/time-picker/index.tsxindex e101750332f..3d8fc5a5e3a 100644--- a/packages/dify-ui/src/date-time/time-picker/index.tsx+++ b/packages/dify-ui/src/date-time/time-picker/index.tsx@@ -33,6 +33,7 @@ import { usePickerValue } from '../internal/use-picker-value'type TimePickerLabels = TimePanelLabels & {title: string+ close: stringnow: stringapply: stringunavailable: string@@ -55,8 +56,9 @@ type TimePickerProps = PickerFieldProps &}type ContextValue = Omit<TimePickerProps,- 'value' | 'defaultValue' | 'onValueChange' | 'children'+ 'value' | 'defaultValue' | 'onValueChange' | 'children' | 'labels'> & {+ labels: TimePickerLabelsvalue: Exclude<TimePickerProps['value'], undefined>commit: (value: string | null, details: TimePickerChangeEventDetails) => boolean}@@ -68,6 +70,7 @@ function useContext() {}const defaultLabels: TimePickerLabels = {title: 'Pick Time',+ close: 'Close',hour: 'Hour',minute: 'Minute',period: 'Period',@@ -99,16 +102,14 @@ function TimePicker({(props.isTimeUnavailable?.(value) || Number(value.slice(3)) % (props.minuteStep ?? 1) !== 0),)+ const labels = { ...defaultLabels, ...props.labels }+return (- <Context.Provider value={{ ...props, value, commit }}>+ <Context.Provider value={{ ...props, value, commit, labels }}><PickerRoot{...props}invalid={props.invalid || unavailable}- validationMessage={- unavailable- ? (props.labels?.unavailable ?? defaultLabels.unavailable)- : props.validationMessage- }+ validationMessage={unavailable ? labels.unavailable : props.validationMessage}placeholder={props.placeholder ?? 'Select time'}displayValue={value@@ -154,9 +155,9 @@ const TimePickerClear = PickerClearconst TimePickerLabel = PickerLabelconst TimePickerValue = PickerValuefunction TimePickerContent(props: TimePickerContentProps) {- const { value, timeZone } = useContext()+ const { value, timeZone, labels } = useContext()return (- <PickerContent {...props}>+ <PickerContent {...props} closeLabel={labels.close}><Session key={`${value ?? ''}-${timeZone ?? ''}`} /></PickerContent>)@@ -181,7 +182,6 @@ function Session() {} = useContext()const { close, canEdit } = usePickerContext()const [draft, setDraft] = React.useState(() => value ?? currentTime(timeZone, minuteStep))- const text = { ...defaultLabels, ...labels }const unavailable = Boolean(isTimeUnavailable?.(draft) || Number(draft.slice(3)) % minuteStep !== 0,)@@ -189,11 +189,11 @@ function Session() {const errorId = React.useId()return (<PickerPanel- header={<PickerPanelHeader>{text.title}</PickerPanelHeader>}+ header={<PickerPanelHeader>{labels.title}</PickerPanelHeader>}message={unavailable && (<p id={errorId} role="status" className="px-2 system-xs-regular text-text-destructive">- {text.unavailable}+ {labels.unavailable}</p>)}@@ -207,7 +207,7 @@ function Session() {requestScroll()}}>- {text.now}+ {labels.now}</Button><Buttonvariant="primary"@@ -226,7 +226,7 @@ function Session() {close()}}>- {text.apply}+ {labels.apply}</Button></React.Fragment>}@@ -236,7 +236,7 @@ function Session() {scrollRequest={scrollRequest}value={draft}onValueChange={setDraft}- labels={text}+ labels={labels}locale={locale}hourCycle={hourCycle}/>diff --git a/web/app/components/base/date-time-picker/__tests__/localization.spec.tsx b/web/app/components/base/date-time-picker/__tests__/localization.spec.tsxindex 0c5a6c6261c..8020e37b6e1 100644--- a/web/app/components/base/date-time-picker/__tests__/localization.spec.tsx+++ b/web/app/components/base/date-time-picker/__tests__/localization.spec.tsx@@ -160,3 +160,22 @@ it.each([vi.useRealTimers()}})++it('localizes the picker close action and dismisses without changing its value', async () => {+ const user = userEvent.setup()+ const i18n = await createI18n('zh-Hans')+ const changed = vi.fn()+ render(+ <I18nextProvider i18n={i18n}>+ <TimePicker defaultValue="13:30" onValueChange={changed}>+ <TimePickerLabel>Time</TimePickerLabel>+ <TimePickerTrigger />+ <TimePickerContent />+ </TimePicker>+ </I18nextProvider>,+ )+ await user.click(screen.getByRole('button', { name: /^Time / }))+ act(() => screen.getByRole('button', { name: zh['operation.close'] }).click())+ expect(screen.queryByRole('dialog')).not.toBeInTheDocument()+ expect(changed).not.toHaveBeenCalled()+})diff --git a/web/app/components/base/date-time-picker/use-picker-labels.ts b/web/app/components/base/date-time-picker/use-picker-labels.tsindex fe4cfd33b62..6d912a4eb96 100644--- a/web/app/components/base/date-time-picker/use-picker-labels.ts+++ b/web/app/components/base/date-time-picker/use-picker-labels.ts@@ -26,6 +26,7 @@ export function usePickerLabels() {unavailable: t(($) => $['picker.unavailable']),backToDate: t(($) => $['operation.pickDate']),cancel: t(($) => $['operation.cancel']),+ close: t(($) => $['operation.close']),apply: t(($) => $['operation.ok']),now: t(($) => $['operation.now']),title: t(($) => $['title.pickTime']),diff --git a/web/i18n/locales/ar-TN/time.json b/web/i18n/locales/ar-TN/time.jsonindex 1067a5ca510..868491a45df 100644--- a/web/i18n/locales/ar-TN/time.json+++ b/web/i18n/locales/ar-TN/time.json@@ -2,6 +2,7 @@"dateFormats.compact": "MM/DD/YYYY HH:mm","dateFormats.withSeconds": "MM/DD/YYYY hh:mm:ss A","operation.cancel": "إلغاء",+ "operation.close": "إغلاق","operation.now": "الآن","operation.ok": "موافق","operation.pickDate": "اختر التاريخ",diff --git a/web/i18n/locales/az-AZ/time.json b/web/i18n/locales/az-AZ/time.jsonindex 4d9f21a0728..d210b8d9121 100644--- a/web/i18n/locales/az-AZ/time.json+++ b/web/i18n/locales/az-AZ/time.json@@ -2,6 +2,7 @@"dateFormats.compact": "DD.MM.YYYY HH:mm","dateFormats.withSeconds": "DD.MM.YYYY HH:mm:ss","operation.cancel": "Ləğv et",+ "operation.close": "Bağla","operation.now": "İndi","operation.ok": "Təsdiqlə","operation.pickDate": "Tarix seç",diff --git a/web/i18n/locales/de-DE/time.json b/web/i18n/locales/de-DE/time.jsonindex c6fd15e5fbe..7096a430242 100644--- a/web/i18n/locales/de-DE/time.json+++ b/web/i18n/locales/de-DE/time.json@@ -2,6 +2,7 @@"dateFormats.compact": "MM/DD/YYYY HH:mm","dateFormats.withSeconds": "MM/DD/YYYY hh:mm:ss A","operation.cancel": "Stornieren",+ "operation.close": "Schließen","operation.now": "Jetzt","operation.ok": "OK","operation.pickDate": "Datum auswählen",diff --git a/web/i18n/locales/en-US/time.json b/web/i18n/locales/en-US/time.jsonindex fd54a29e68b..c79bf198d2a 100644--- a/web/i18n/locales/en-US/time.json+++ b/web/i18n/locales/en-US/time.json@@ -2,6 +2,7 @@"dateFormats.compact": "MM/DD/YYYY HH:mm","dateFormats.withSeconds": "MM/DD/YYYY hh:mm:ss A","operation.cancel": "Cancel",+ "operation.close": "Close","operation.now": "Now","operation.ok": "OK","operation.pickDate": "Pick Date",diff --git a/web/i18n/locales/es-ES/time.json b/web/i18n/locales/es-ES/time.jsonindex 84f88123f0e..a05039ecaf5 100644--- a/web/i18n/locales/es-ES/time.json+++ b/web/i18n/locales/es-ES/time.json@@ -2,6 +2,7 @@"dateFormats.compact": "MM/DD/YYYY HH:mm","dateFormats.withSeconds": "MM/DD/YYYY hh:mm:ss A","operation.cancel": "Cancelar",+ "operation.close": "Cerrar","operation.now": "Ahora","operation.ok": "De acuerdo","operation.pickDate": "Seleccionar fecha",diff --git a/web/i18n/locales/fa-IR/time.json b/web/i18n/locales/fa-IR/time.jsonindex 91cd2fd5a50..cd4e5b0b1ed 100644--- a/web/i18n/locales/fa-IR/time.json+++ b/web/i18n/locales/fa-IR/time.json@@ -2,6 +2,7 @@"dateFormats.compact": "MM/DD/YYYY HH:mm","dateFormats.withSeconds": "MM/DD/YYYY hh:mm:ss A","operation.cancel": "لغو",+ "operation.close": "بستن","operation.now": "حالا","operation.ok": "خوب","operation.pickDate": "تاریخ را انتخاب کنید",diff --git a/web/i18n/locales/fr-FR/time.json b/web/i18n/locales/fr-FR/time.jsonindex 8a8241f46b9..2cee27f280b 100644--- a/web/i18n/locales/fr-FR/time.json+++ b/web/i18n/locales/fr-FR/time.json@@ -2,6 +2,7 @@"dateFormats.compact": "DD/MM/YYYY HH:mm","dateFormats.withSeconds": "MM/DD/YYYY hh:mm:ss A","operation.cancel": "Annuler",+ "operation.close": "Fermer","operation.now": "Maintenant","operation.ok": "D'accord","operation.pickDate": "Choisir une date",diff --git a/web/i18n/locales/hi-IN/time.json b/web/i18n/locales/hi-IN/time.jsonindex b8fd79d8b15..f4db14b1ddb 100644--- a/web/i18n/locales/hi-IN/time.json+++ b/web/i18n/locales/hi-IN/time.json@@ -2,6 +2,7 @@"dateFormats.compact": "MM/DD/YYYY HH:mm","dateFormats.withSeconds": "MM/DD/YYYY hh:mm:ss A","operation.cancel": "रद्द करें",+ "operation.close": "बंद करना","operation.now": "अब","operation.ok": "ठीक है","operation.pickDate": "तारीख़ चुनें",diff --git a/web/i18n/locales/id-ID/time.json b/web/i18n/locales/id-ID/time.jsonindex 2da182850d0..fc7e01bef1d 100644--- a/web/i18n/locales/id-ID/time.json+++ b/web/i18n/locales/id-ID/time.json@@ -2,6 +2,7 @@"dateFormats.compact": "MM/DD/YYYY HH:mm","dateFormats.withSeconds": "MM/DD/YYYY hh:mm:ss A","operation.cancel": "Membatalkan",+ "operation.close": "Tutup","operation.now": "Sekarang","operation.ok": "OKE","operation.pickDate": "Tanggal Pilih",diff --git a/web/i18n/locales/it-IT/time.json b/web/i18n/locales/it-IT/time.jsonindex ba94de48cf9..1074fb8efd6 100644--- a/web/i18n/locales/it-IT/time.json+++ b/web/i18n/locales/it-IT/time.json@@ -2,6 +2,7 @@"dateFormats.compact": "DD/MM/YYYY HH:mm","dateFormats.withSeconds": "MM/DD/YYYY hh:mm:ss A","operation.cancel": "Annulla",+ "operation.close": "Chiudere","operation.now": "Ora","operation.ok": "OK","operation.pickDate": "Seleziona Data",diff --git a/web/i18n/locales/ja-JP/time.json b/web/i18n/locales/ja-JP/time.jsonindex dd875f8a364..e222a9738e2 100644--- a/web/i18n/locales/ja-JP/time.json+++ b/web/i18n/locales/ja-JP/time.json@@ -2,6 +2,7 @@"dateFormats.compact": "YYYY/MM/DD HH:mm","dateFormats.withSeconds": "YYYY/MM/DD hh:mm:ss A","operation.cancel": "キャンセル",+ "operation.close": "閉じる","operation.now": "今","operation.ok": "はい","operation.pickDate": "日付を選択",diff --git a/web/i18n/locales/ko-KR/time.json b/web/i18n/locales/ko-KR/time.jsonindex eb03fb9f1c4..848d838e43b 100644--- a/web/i18n/locales/ko-KR/time.json+++ b/web/i18n/locales/ko-KR/time.json@@ -2,6 +2,7 @@"dateFormats.compact": "MM/DD/YYYY HH:mm","dateFormats.withSeconds": "YYYY/MM/DD HH:mm:ss","operation.cancel": "취소",+ "operation.close": "닫기","operation.now": "오늘","operation.ok": "좋아요","operation.pickDate": "날짜 선택",diff --git a/web/i18n/locales/lo-LA/time.json b/web/i18n/locales/lo-LA/time.jsonindex b79ec0cdb0d..9e46f73c819 100644--- a/web/i18n/locales/lo-LA/time.json+++ b/web/i18n/locales/lo-LA/time.json@@ -2,6 +2,7 @@"dateFormats.compact": "MM/DD/YYYY HH:mm","dateFormats.withSeconds": "DD/MM/YYYY hh:mm:ss A","operation.cancel": "ຍົກເລີກ",+ "operation.close": "ປິດ","operation.now": "ດຽວນີ້","operation.ok": "ຕົກລົງ","operation.pickDate": "ເລືອກວັນທີ",diff --git a/web/i18n/locales/nl-NL/time.json b/web/i18n/locales/nl-NL/time.jsonindex faca4703124..49c1e843079 100644--- a/web/i18n/locales/nl-NL/time.json+++ b/web/i18n/locales/nl-NL/time.json@@ -2,6 +2,7 @@"dateFormats.compact": "MM/DD/YYYY HH:mm","dateFormats.withSeconds": "MM/DD/YYYY hh:mm:ss A","operation.cancel": "Cancel",+ "operation.close": "Sluiten","operation.now": "Now","operation.ok": "OK","operation.pickDate": "Pick Date",diff --git a/web/i18n/locales/pl-PL/time.json b/web/i18n/locales/pl-PL/time.jsonindex 5152e70df42..2c866a32687 100644--- a/web/i18n/locales/pl-PL/time.json+++ b/web/i18n/locales/pl-PL/time.json@@ -2,6 +2,7 @@"dateFormats.compact": "MM/DD/YYYY HH:mm","dateFormats.withSeconds": "DD/MM/YYYY HH:mm:ss","operation.cancel": "Anuluj",+ "operation.close": "Zamknij","operation.now": "Teraz","operation.ok": "OK","operation.pickDate": "Wybierz datę",diff --git a/web/i18n/locales/pt-BR/time.json b/web/i18n/locales/pt-BR/time.jsonindex 84a57077f34..4e38b67e9f8 100644--- a/web/i18n/locales/pt-BR/time.json+++ b/web/i18n/locales/pt-BR/time.json@@ -2,6 +2,7 @@"dateFormats.compact": "DD/MM/YYYY HH:mm","dateFormats.withSeconds": "MM/DD/YYYY hh:mm:ss A","operation.cancel": "Cancelar",+ "operation.close": "Fechar","operation.now": "Agora","operation.ok": "OK","operation.pickDate": "Escolher Data",diff --git a/web/i18n/locales/ro-RO/time.json b/web/i18n/locales/ro-RO/time.jsonindex 6e0ad833740..8ccfd604e66 100644--- a/web/i18n/locales/ro-RO/time.json+++ b/web/i18n/locales/ro-RO/time.json@@ -2,6 +2,7 @@"dateFormats.compact": "MM/DD/YYYY HH:mm","dateFormats.withSeconds": "DD/MM/YYYY hh:mm:ss A","operation.cancel": "Anulează",+ "operation.close": "Închide","operation.now": "Acum","operation.ok": "Bine","operation.pickDate": "Alege o dată",diff --git a/web/i18n/locales/ru-RU/time.json b/web/i18n/locales/ru-RU/time.jsonindex c68967fe09d..afe80272c3f 100644--- a/web/i18n/locales/ru-RU/time.json+++ b/web/i18n/locales/ru-RU/time.json@@ -2,6 +2,7 @@"dateFormats.compact": "MM/DD/YYYY HH:mm","dateFormats.withSeconds": "DD.MM.YYYY HH:mm:ss","operation.cancel": "Отмена",+ "operation.close": "Закрыть","operation.now": "Теперь","operation.ok": "Хорошо","operation.pickDate": "Выберите дату",diff --git a/web/i18n/locales/sl-SI/time.json b/web/i18n/locales/sl-SI/time.jsonindex 59b2fc82493..b5558f13428 100644--- a/web/i18n/locales/sl-SI/time.json+++ b/web/i18n/locales/sl-SI/time.json@@ -2,6 +2,7 @@"dateFormats.compact": "MM/DD/YYYY HH:mm","dateFormats.withSeconds": "DD.MM.YYYY hh:mm:ss A","operation.cancel": "Prekliči",+ "operation.close": "Zapri","operation.now": "Zdaj","operation.ok": "V redu","operation.pickDate": "Izberi datum",diff --git a/web/i18n/locales/th-TH/time.json b/web/i18n/locales/th-TH/time.jsonindex 145e0cd400f..11191512ec8 100644--- a/web/i18n/locales/th-TH/time.json+++ b/web/i18n/locales/th-TH/time.json@@ -2,6 +2,7 @@"dateFormats.compact": "MM/DD/YYYY HH:mm","dateFormats.withSeconds": "MM/DD/YYYY hh:mm:ss A","operation.cancel": "ยกเลิก",+ "operation.close": "ปิด","operation.now": "ตอนนี้","operation.ok": "ตกลง","operation.pickDate": "เลือกวันที่",diff --git a/web/i18n/locales/tr-TR/time.json b/web/i18n/locales/tr-TR/time.jsonindex 3df4fdfc00f..6dcebb021ae 100644--- a/web/i18n/locales/tr-TR/time.json+++ b/web/i18n/locales/tr-TR/time.json@@ -2,6 +2,7 @@"dateFormats.compact": "DD/MM/YYYY HH:mm","dateFormats.withSeconds": "DD/MM/YYYY HH:mm:ss","operation.cancel": "İptal",+ "operation.close": "Kapat","operation.now": "Şimdi","operation.ok": "Tamam","operation.pickDate": "Tarih Seç",diff --git a/web/i18n/locales/uk-UA/time.json b/web/i18n/locales/uk-UA/time.jsonindex 06d2186f81c..45b772350b8 100644--- a/web/i18n/locales/uk-UA/time.json+++ b/web/i18n/locales/uk-UA/time.json@@ -2,6 +2,7 @@"dateFormats.compact": "DD.MM.YYYY HH:mm","dateFormats.withSeconds": "MM/DD/YYYY hh:mm:ss A","operation.cancel": "Скасувати",+ "operation.close": "Закрити","operation.now": "Тепер","operation.ok": "Добре","operation.pickDate": "Виберіть дату",diff --git a/web/i18n/locales/vi-VN/time.json b/web/i18n/locales/vi-VN/time.jsonindex a28cc1c1db7..f2a56c3c22f 100644--- a/web/i18n/locales/vi-VN/time.json+++ b/web/i18n/locales/vi-VN/time.json@@ -2,6 +2,7 @@"dateFormats.compact": "DD/MM/YYYY HH:mm","dateFormats.withSeconds": "MM/DD/YYYY hh:mm:ss A","operation.cancel": "Hủy bỏ",+ "operation.close": "Đóng","operation.now": "Bây giờ","operation.ok": "Được rồi","operation.pickDate": "Chọn Ngày",diff --git a/web/i18n/locales/zh-Hans/time.json b/web/i18n/locales/zh-Hans/time.jsonindex afbe72aa1ec..9ca81b5973e 100644--- a/web/i18n/locales/zh-Hans/time.json+++ b/web/i18n/locales/zh-Hans/time.json@@ -2,6 +2,7 @@"dateFormats.compact": "YYYY/MM/DD HH:mm","dateFormats.withSeconds": "YYYY-MM-DD HH:mm:ss","operation.cancel": "取消",+ "operation.close": "关闭","operation.now": "此刻","operation.ok": "确定","operation.pickDate": "选择日期",diff --git a/web/i18n/locales/zh-Hant/time.json b/web/i18n/locales/zh-Hant/time.jsonindex 7ffa4f411f2..92c3de2d98a 100644--- a/web/i18n/locales/zh-Hant/time.json+++ b/web/i18n/locales/zh-Hant/time.json@@ -2,6 +2,7 @@"dateFormats.compact": "YYYY/MM/DD HH:mm","dateFormats.withSeconds": "YYYY-MM-DD HH:mm:ss","operation.cancel": "取消",+ "operation.close": "關閉","operation.now": "現在","operation.ok": "好","operation.pickDate": "選擇日期",diff --git a/web/i18n/resources.generated.d.ts b/web/i18n/resources.generated.d.tsindex 8cd543849c5..f8938e56427 100644--- a/web/i18n/resources.generated.d.ts+++ b/web/i18n/resources.generated.d.ts@@ -5143,6 +5143,7 @@ export default interface Resources {'dateFormats.compact': 'MM/DD/YYYY HH:mm''dateFormats.withSeconds': 'MM/DD/YYYY hh:mm:ss A''operation.cancel': 'Cancel'+ 'operation.close': 'Close''operation.now': 'Now''operation.ok': 'OK''operation.pickDate': 'Pick Date'