Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(DateTimeInput): a press in the time input keeps the preset-time list open (#9459)

Cindy Zhangfc44bc3b7204
diff --git a/.changeset/datetimeinput-time-press-keeps-list.md b/.changeset/datetimeinput-time-press-keeps-list.md
new file mode 100644
index 0000000000..e4be642eb2
--- /dev/null
+++ b/.changeset/datetimeinput-time-press-keeps-list.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] A press in a DateTimeInput's own time input no longer closes its open list of preset times. Clicking into the time text to fix a digit keeps the list showing; a press anywhere else on the page, moving focus away and Escape still close it.
+
+@cixzhang
diff --git a/docs/architecture/layer-runtime.md b/docs/architecture/layer-runtime.md
index 568cb51d22..7541c038c5 100644
--- a/docs/architecture/layer-runtime.md
+++ b/docs/architecture/layer-runtime.md
@@ -299,13 +299,13 @@ during a press so native light dismissal does not mistake them for outside
interaction. Their click action is cancelled as an invoker toggle so the control
can perform its own action without closing the layer.
-A text input cannot be an invoker, so BaseTypeahead's list, which its text field
-owns, is a manual popover. A press that starts and ends on the field's input or
+A text input cannot be an invoker, so BaseTypeahead's list and DateTimeInput's
+time list, which their text fields own, are manual popovers. A press that starts and ends on the field's input or
its buttons, or in the list, is inside, judged across open shadow roots; a press
that starts and ends anywhere else closes the list, a scroll or pinch that
starts outside does not, and Escape stays on the shared stack. Implementation
-gap: DateTimeInput's time list, DateInput's calendar and ChatComposerInput's
-trigger menu are still auto popovers with native light dismiss, so a press in
+gap: DateInput's calendar and ChatComposerInput's trigger menu are still auto
+popovers with native light dismiss, so a press in
their own text input closes them.
### Current dismissal plumbing
@@ -332,7 +332,8 @@ Outside interaction is not coordinated by the shared stack. Current paths are
independent:
- auto popovers use native light dismiss;
-- BaseTypeahead's list, a manual popover, uses Layer's outside-press watch,
+- BaseTypeahead's list and DateTimeInput's time list, manual popovers, use
+ Layer's outside-press watch,
which closes on a press that starts and ends outside the field and the list
and forgets a cancelled press (a scroll);
- native dialogs handle backdrop clicks locally;
@@ -651,7 +652,7 @@ staged as `[breaking]` (`spec:AST-017` FR32).
- `Layer/useTouchTrigger.ts` owns touch trigger classification and the current
touch-only outside listener for Tooltip/HoverCard.
- `Layer/outsidePress.ts` owns the outside-press watch for a text field's
- manual layer, used by BaseTypeahead.
+ manual layer, used by BaseTypeahead and DateTimeInput.
- `DropdownMenuContext` and `DropdownMenuSubMenu` own the current local
menu-cascade parent-close chain.
- Dialog families own native modal/backdrop presentation and their local channel
diff --git a/docs/specs/components/DateTimeInput/DateTimeInput.spec.md b/docs/specs/components/DateTimeInput/DateTimeInput.spec.md
index 2d18b3adf3..8bcc53f8f7 100644
--- a/docs/specs/components/DateTimeInput/DateTimeInput.spec.md
+++ b/docs/specs/components/DateTimeInput/DateTimeInput.spec.md
@@ -109,17 +109,17 @@ Consumer migration instructions belong in consumer docs and release notes.
## Behavioral and layout contract
-| ID | Invariant | Basis |
-| --- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------- |
-| FR1 | DateTimeInput MUST reflect one controlled date-time value across its visible segments and active picker, and MUST NOT reveal a competing selected date after the parent accepts a clear. | Public docs, controlled component seam, current source, focused tests |
-| FR2 | Every committed date or time change MUST emit one valid combined ISO date-time value; clearing MUST emit `undefined`; changing time while no date is committed MUST emit nothing. | Public types, docs, current source, focused tests |
-| FR3 | `presentation`, deprecated `nativePicker`, precedence, pointer adaptation, forced surfaces, and per-segment native fallbacks MUST follow `spec:AST-043` FR1–FR4. The touch date sheet's month heading and month-pane names follow `component:DateInput` FR6. | `spec:AST-043` |
-| FR4 | When `changeAction` is present, every value-change path MUST call `onChange` first, show the proposed controlled value optimistically, and contribute to one busy state until the controlled value accepts or replaces it. | `family:input-fields/FR6` |
-| FR5 | The two pointer segments share one row while each retains its intrinsic basis; when the container is narrower, flex wrapping moves them into separate full-width rows. Each segment is the shared element height for its size, as a minimum that grows with a set text size under `spec:AST-102` FR4. Implementation gap: the height is fixed at that size. | Public docs, current source, focused layout tests; `spec:AST-102` FR4 |
-| FR6 | Date-time bounds and date constraints MUST prevent invalid commits. Native controls MAY receive platform hints, but JavaScript validation remains the final commit boundary; calendar-only options MAY be unavailable on native surfaces. | Public docs, current source, focused presentation tests |
-| FR7 | A preset-time listbox MUST remain optional, preserve typed entry, expose one selected option independently from keyboard highlight, and limit offered values to the selected date's effective minimum and maximum. Time text and typed times MUST follow the active locale's digits, separator, and day-period words (`architecture:internationalization` INV1a, INV8). The hour format is `hourFormat` when set, else the provider locale's hour cycle; time text, preset options, and the stepped-time announcement come from the shared time formatter, and typed times parse the locale's digits, separators, and day-period words as well as English. Implementation gap: the typed time field commits as soon as a prefix parses. | Public docs, current source, focused interaction tests; `architecture:internationalization` INV1a, INV8 |
-| FR8 | Base props and `ref` MUST reach the date segment's input; a caller `aria-describedby` joins the component's own descriptions, and a caller DOM handler runs after the field's own handler. `container*` reaches the Field box and `control*` the segment row; root `xstyle`, `className`, and `style` are not accepted. | `family:input-fields` FR10; `DateTimeInput.fr10.test.tsx` |
-| FR9 | A disabled field MUST keep both segments focusable with `aria-disabled` and no native `disabled`, block every value-changing path, keep the calendar button's tab stop, and paint the keyboard focus ring. Explicit `isLoading` makes every surface inert the same way; a pending `changeAction` does so only on the popover surface, and the bottom sheet and any field with a native date segment keep accepting edits. The busy start is announced once. Implementation gap: a caller `onKeyDown` and other DOM handlers on the date segment still run while disabled (`spec:AST-085` FR2). Implementation gap: a busy field that is not disabled takes the disabled paint (half opacity), on every surface while `isLoading` and on the popover while a `changeAction` is pending, against `spec:AST-085` FR6. | `spec:AST-085` FR1, FR2, FR6; `spec:AST-086` FR8; current source and tests |
+| ID | Invariant | Basis |
+| --- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
+| FR1 | DateTimeInput MUST reflect one controlled date-time value across its visible segments and active picker, and MUST NOT reveal a competing selected date after the parent accepts a clear. | Public docs, controlled component seam, current source, focused tests |
+| FR2 | Every committed date or time change MUST emit one valid combined ISO date-time value; clearing MUST emit `undefined`; changing time while no date is committed MUST emit nothing. | Public types, docs, current source, focused tests |
+| FR3 | `presentation`, deprecated `nativePicker`, precedence, pointer adaptation, forced surfaces, and per-segment native fallbacks MUST follow `spec:AST-043` FR1–FR4. The touch date sheet's month heading and month-pane names follow `component:DateInput` FR6. | `spec:AST-043` |
+| FR4 | When `changeAction` is present, every value-change path MUST call `onChange` first, show the proposed controlled value optimistically, and contribute to one busy state until the controlled value accepts or replaces it. | `family:input-fields/FR6` |
+| FR5 | The two pointer segments share one row while each retains its intrinsic basis; when the container is narrower, flex wrapping moves them into separate full-width rows. Each segment is the shared element height for its size, as a minimum that grows with a set text size under `spec:AST-102` FR4. Implementation gap: the height is fixed at that size. | Public docs, current source, focused layout tests; `spec:AST-102` FR4 |
+| FR6 | Date-time bounds and date constraints MUST prevent invalid commits. Native controls MAY receive platform hints, but JavaScript validation remains the final commit boundary; calendar-only options MAY be unavailable on native surfaces. | Public docs, current source, focused presentation tests |
+| FR7 | A preset-time listbox MUST remain optional, preserve typed entry, expose one selected option independently from keyboard highlight, and limit offered values to the selected date's effective minimum and maximum. Time text and typed times MUST follow the active locale's digits, separator, and day-period words (`architecture:internationalization` INV1a, INV8). The hour format is `hourFormat` when set, else the provider locale's hour cycle; time text, preset options, and the stepped-time announcement come from the shared time formatter, and typed times parse the locale's digits, separators, and day-period words as well as English. Implementation gap: the typed time field commits as soon as a prefix parses. While open, the listbox stays open for a press on the time field or in the listbox and closes for a press elsewhere (`architecture:layer-runtime`). | Public docs, current source, focused interaction tests; `architecture:internationalization` INV1a, INV8 |
+| FR8 | Base props and `ref` MUST reach the date segment's input; a caller `aria-describedby` joins the component's own descriptions, and a caller DOM handler runs after the field's own handler. `container*` reaches the Field box and `control*` the segment row; root `xstyle`, `className`, and `style` are not accepted. | `family:input-fields` FR10; `DateTimeInput.fr10.test.tsx` |
+| FR9 | A disabled field MUST keep both segments focusable with `aria-disabled` and no native `disabled`, block every value-changing path, keep the calendar button's tab stop, and paint the keyboard focus ring. Explicit `isLoading` makes every surface inert the same way; a pending `changeAction` does so only on the popover surface, and the bottom sheet and any field with a native date segment keep accepting edits. The busy start is announced once. Implementation gap: a caller `onKeyDown` and other DOM handlers on the date segment still run while disabled (`spec:AST-085` FR2). Implementation gap: a busy field that is not disabled takes the disabled paint (half opacity), on every surface while `isLoading` and on the popover while a `changeAction` is pending, against `spec:AST-085` FR6. | `spec:AST-085` FR1, FR2, FR6; `spec:AST-086` FR8; current source and tests |
### Allowed variation
@@ -233,15 +233,15 @@ leading clock glyph uses `date-time-input-clock-icon`.
## Verification map
-| Contract | Verification | Representative states | Mutation or failure expectation | Audit section |
-| ------------------- | ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------- |
-| FR1–FR2 | `DateTimeInput.test.tsx` | empty, calendar selection, typed date/time, clear | A stale Calendar selection, partial output, or invalid mutation makes a public-state test fail. | `audit:DateTimeInput/behavior` |
-| FR3, FR6 | `Presentation.test.tsx`, `NativePickerSegments.test.tsx`, `DateTimeInputTouch.test.tsx` | forced, adaptive, legacy, native fallback, constrained commit | A substituted surface, precedence drift, or invalid commit makes a presentation test fail. | `audit:DateTimeInput/surfaces` |
-| FR4, FR9, AR4 | `DateTimeInput.test.tsx`, `DateTimeInputTouch.test.tsx`; `BusyOwnerAnnouncement.test.tsx` DateTimeInput case | pending, loading, disabled reason | Mutation during busy/disabled state or stale optimistic output makes a state test fail. Evidence gap: no test asserts that caller handlers still run while disabled. | `audit:DateTimeInput/state` |
-| FR5 | `DateTimeInput.test.tsx` | intrinsic row, narrow-container wrap classes | Removing the intrinsic basis or wrap styles makes the class-level layout assertions fail; rendered geometry remains review evidence. Evidence gap: no test asserts segment heights or text growth. | `audit:DateTimeInput/layout` |
-| FR7, AR1–AR3 | `DateTimeInput.test.tsx`, `DateTimeInputTouch.test.tsx` | popovers, time options, keyboard/focus | Wrong role, name, state, keyboard behavior, or focus behavior makes a focused interaction test fail. A provider-locale test asserts the closed time text follows the locale's hour cycle and day period; the shared formatter's tests cover parsing. | `audit:DateTimeInput/interaction` |
-| FR8 | `DateTimeInput.fr10.test.tsx` | each surface; caller id, describedby, onClick, onKeyDown | A base prop off the date input, a dropped caller description, or styling on the wrong part fails. | `audit:DateTimeInput/api` |
-| Theming anatomy map | `scripts/check-knowledge.mjs`, `themingTargets.test.ts` | root, segments, icons, listbox, options | Missing, undocumented, or wrongly placed targets fail knowledge or target checks. | `audit:DateTimeInput/theming` |
+| Contract | Verification | Representative states | Mutation or failure expectation | Audit section |
+| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------- |
+| FR1–FR2 | `DateTimeInput.test.tsx` | empty, calendar selection, typed date/time, clear | A stale Calendar selection, partial output, or invalid mutation makes a public-state test fail. | `audit:DateTimeInput/behavior` |
+| FR3, FR6 | `Presentation.test.tsx`, `NativePickerSegments.test.tsx`, `DateTimeInputTouch.test.tsx` | forced, adaptive, legacy, native fallback, constrained commit | A substituted surface, precedence drift, or invalid commit makes a presentation test fail. | `audit:DateTimeInput/surfaces` |
+| FR4, FR9, AR4 | `DateTimeInput.test.tsx`, `DateTimeInputTouch.test.tsx`; `BusyOwnerAnnouncement.test.tsx` DateTimeInput case | pending, loading, disabled reason | Mutation during busy/disabled state or stale optimistic output makes a state test fail. Evidence gap: no test asserts that caller handlers still run while disabled. | `audit:DateTimeInput/state` |
+| FR5 | `DateTimeInput.test.tsx` | intrinsic row, narrow-container wrap classes | Removing the intrinsic basis or wrap styles makes the class-level layout assertions fail; rendered geometry remains review evidence. Evidence gap: no test asserts segment heights or text growth. | `audit:DateTimeInput/layout` |
+| FR7, AR1–AR3 | `DateTimeInput.test.tsx`, `DateTimeInputTouch.test.tsx`; `DateTimeInput.test.tsx` "keeps the time list open on a press in the time input, closes it on a press elsewhere" | popovers, time options, keyboard/focus | Wrong role, name, state, keyboard behavior, or focus behavior makes a focused interaction test fail. A provider-locale test asserts the closed time text follows the locale's hour cycle and day period; the shared formatter's tests cover parsing. | `audit:DateTimeInput/interaction` |
+| FR8 | `DateTimeInput.fr10.test.tsx` | each surface; caller id, describedby, onClick, onKeyDown | A base prop off the date input, a dropped caller description, or styling on the wrong part fails. | `audit:DateTimeInput/api` |
+| Theming anatomy map | `scripts/check-knowledge.mjs`, `themingTargets.test.ts` | root, segments, icons, listbox, options | Missing, undocumented, or wrongly placed targets fail knowledge or target checks. | `audit:DateTimeInput/theming` |
## Current-state impact
diff --git a/packages/core/src/DateTimeInput/DateTimeInput.test.tsx b/packages/core/src/DateTimeInput/DateTimeInput.test.tsx
index c78347ca84..bc000b3d85 100644
--- a/packages/core/src/DateTimeInput/DateTimeInput.test.tsx
+++ b/packages/core/src/DateTimeInput/DateTimeInput.test.tsx
@@ -1759,9 +1759,50 @@ describe('DateTimeInput', () => {
expect(timeInput).toHaveAttribute('aria-expanded', 'false');
});
+ // architecture:layer-runtime: a press on the time field is inside its list.
+ it('keeps the time list open on a press in the time input, closes it on a press elsewhere', async () => {
+ const press = (target: Element) => {
+ fireEvent.pointerDown(target, {composed: true});
+ fireEvent.pointerUp(target, {composed: true});
+ };
+ render(
+ <>
+ <DateTimeInput
+ label="Meeting"
+ value={'2026-03-15T14:00' as ISODateTimeString}
+ timeOptionInterval={60}
+ onChange={() => {}}
+ />
+ <p>Elsewhere</p>
+ </>,
+ );
+ const timeInput = screen.getByLabelText('Meeting time');
+ fireEvent.keyDown(timeInput, {key: 'ArrowDown', altKey: true});
+ expect(timeInput).toHaveAttribute('aria-expanded', 'true');
+ const listbox = document.getElementById(
+ timeInput.getAttribute('aria-controls')!,
+ );
+ // The list is a manual popover, so the browser does not light-dismiss
+ // it on a press in the time input.
+ expect(listbox?.closest('[popover]')).toHaveAttribute(
+ 'popover',
+ 'manual',
+ );
+
+ press(timeInput);
+ expect(timeInput).toHaveAttribute('aria-expanded', 'true');
+ press(listbox!);
+ expect(timeInput).toHaveAttribute('aria-expanded', 'true');
+
+ press(screen.getByText('Elsewhere'));
+ await waitFor(() => {
+ expect(timeInput).toHaveAttribute('aria-expanded', 'false');
+ });
+ });
+
it('closes the list when focus leaves the field entirely', () => {
- // Light dismiss covers outside clicks and Escape, never a programmatic
- // focus move. Without this the listbox is orphaned in the top layer.
+ // The outside-press watch covers outside presses and Escape stays on the
+ // layer stack, never a programmatic focus move. Without this the listbox is orphaned in the top layer.
render(
<>
<DateTimeInput
diff --git a/packages/core/src/DateTimeInput/DateTimeInput.tsx b/packages/core/src/DateTimeInput/DateTimeInput.tsx
index 8474c7996f..ed7e0c27d4 100644
--- a/packages/core/src/DateTimeInput/DateTimeInput.tsx
+++ b/packages/core/src/DateTimeInput/DateTimeInput.tsx
@@ -64,6 +64,7 @@ import {
} from '../Calendar';
import {useCalendarConstraints} from '../Calendar/hooks';
import {usePopover} from '../Popover';
+import {useOutsidePress} from '../Layer/outsidePress';
import {useTooltip} from '../Tooltip';
import {useInputContainer} from '../hooks/useInputContainer';
import {useBusyAnnouncement} from '../hooks/useBusyAnnouncement';
@@ -1150,10 +1151,9 @@ function PointerDateTimeField({
const timeListboxId = useId();
const [highlightedTimeIndex, setHighlightedTimeIndex] = useState(-1);
- // With popover="auto", showing the popover between pointerdown and
- // pointerup/click lets the browser's light-dismiss treat that same click as
- // "outside" and close it again. Defer the show past the click, as
- // BaseTypeahead does for the same reason.
+ // Defer a show that happens during a press past that press's click, so the
+ // list's outside-press watch starts after the press ends and never judges
+ // it, as BaseTypeahead does.
const timePointerActiveRef = useRef(false);
// Whether the highlight is still the one typing derived, or the user has
@@ -1173,14 +1173,41 @@ function PointerDateTimeField({
);
}, []);
+ // The time list is a manual popover: the browser's light dismiss counts a
+ // press in the time input as outside (a text input cannot be an invoker), so
+ // a press in the field would close the list it just opened. A press on the
+ // time field or in the list is inside; a press anywhere else closes it
+ // (architecture:layer-runtime, component:BaseTypeahead FR12's rule).
+ const timeOutsidePress = useOutsidePress();
const timePopover = usePopover({
- hasLightDismiss: true,
+ hasLightDismiss: false,
hasCloseButton: false,
hasAutoFocus: false,
// The popup's own role="listbox" carries the semantics; the input keeps
// DOM focus, so announcing a dialog here would misrepresent it.
role: 'none',
- onHide: () => setHighlightedTimeIndex(-1),
+ onShow: () => {
+ const field = timeContainerRef.current;
+ if (field == null) {
+ return;
+ }
+ timeOutsidePress.start(
+ field,
+ // The list may be hosted outside the field, so it counts on its own.
+ path =>
+ path.some(
+ target =>
+ target === field ||
+ (target instanceof Element && target.id === timePopover.id),
+ ),
+ // Called after usePopover has returned, so `timePopover` is assigned.
+ () => timePopover.hide(),
+ );
+ },
+ onHide: () => {
+ timeOutsidePress.stop();
+ setHighlightedTimeIndex(-1);
+ },
});
// Anchor the list to the time wrapper, not the date input the field's own
@@ -1417,9 +1444,9 @@ function PointerDateTimeField({
(e: FocusEvent<HTMLInputElement>) => {
setIsTimeFocused(false);
- // Native light dismiss only fires on outside clicks and Escape, so a focus
- // move that is neither — Tab handled elsewhere, or a programmatic focus —
- // would strand the listbox open in the top layer. Focus landing inside the
+ // The outside-press watch only answers pointer presses and Escape stays
+ // on the layer stack, so a focus move that is neither — Tab handled
+ // elsewhere, or a programmatic focus — would strand the listbox open. Focus landing inside the
// field or the popup itself is not a leave. Mirrors BaseTypeahead.
if (timePopover.isOpen) {
const next = e.relatedTarget as Node | null;
@@ -1825,7 +1852,7 @@ function PointerDateTimeField({
}
// On the wrapper, not just the input: clicking the clock icon or the
// padding is routed to the input as a synthetic click, which would
- // otherwise open the list mid-gesture and let light dismiss eat it.
+ // otherwise open the list mid-gesture.
onPointerDown={hasTimeOptions ? markTimePointerActive : undefined}
{...mergeProps(
themeProps('date-time-input-time-segment', {