Skip to content

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

TypeScript

fix(DateInput, DateTimeInput): Enter submits the form when nothing is typed (#9678)

Cindy Zhang443c7f83e24d
diff --git a/.changeset/date-enter-submits-form.md b/.changeset/date-enter-submits-form.md
new file mode 100644
index 0000000000..cbc0c8f299
--- /dev/null
+++ b/.changeset/date-enter-submits-form.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] Pressing Enter in the typable date field of a `DateInput` or `DateTimeInput` (the pointer surface) now submits the surrounding form when nothing is typed, as in any text field. Typed text is still committed first, and that Enter does not submit. A disabled or busy field still does nothing on Enter.
+
+@duytbp
diff --git a/docs/specs/components/DateInput/DateInput.spec.md b/docs/specs/components/DateInput/DateInput.spec.md
index bcf1212a5f..3efde32bd6 100644
--- a/docs/specs/components/DateInput/DateInput.spec.md
+++ b/docs/specs/components/DateInput/DateInput.spec.md
@@ -143,6 +143,7 @@ Consumer migration instructions belong in consumer docs and release notes.
| FR13 | A bottom-sheet picker wheel that comes to rest on a disabled row (outside `min`/`max`) MUST continue to the nearest enabled row, a tie going toward the committed row, and select it there. A wheel resting on its committed row MUST NOT select or commit, even when that row is outside the bounds, so opening a bounded sheet never changes an untouched value: a committed value outside the bounds stays, and an empty field stays empty. This holds for every wheel in the DateInput, TimeInput, and DateTimeInput sheets. | DEC-1; UIDatePicker on the iOS 26.2 simulator; current source |
| FR14 | A shown bottom-sheet picker wheel whose value changes from outside, as when a bound clamps the time after another wheel turned, MUST turn onto the new row rather than jump to it. | UIDatePicker on the iOS 26.2 simulator; current source |
| FR15 | Under a coarse primary pointer, a sheet wheel's pan takes a trackpad's two-finger scroll, as `spec:AST-094` FR43 allows a record to grant: the rows follow the fingers, coast on at the lift with the fingers' last speed, and rest on a row by FR13. A mouse-wheel notch turns the wheel one row, as an arrow key does, with no coast. A ctrl-scroll stays the page's zoom (`spec:AST-094` FR43). Implementation gap: the wheel is the browser's scroll-snap column for both inputs, so a trackpad's momentum runs at the browser's rate and a mouse-wheel notch moves the column by the browser's scroll step, several rows. | `spec:AST-094` FR43; current source |
+| FR16 | Enter in the pointer field's text input commits typed text that has not been committed and is then held back, so a form never submits the value from before the commit. With no typed text pending, Enter is not prevented, so a form submits as it does from any text field, except on a disabled or busy field, where Enter does nothing (`spec:AST-085` FR2). |
### Allowed variation
@@ -322,6 +323,7 @@ clear-glyph target of its own.
| FR13 | `Wheel.test.tsx`, the wheel every sheet renders: "stopping below the minimum travels on to the minimum and commits it there", "stopping past the maximum travels back to the maximum", "a stop on another disabled row still travels to the bounds", "opening on a value outside the bounds parks on it without travelling or committing", "a drag that comes back to rest on a committed value outside the bounds stays there and commits nothing", "never commits a disabled row, even with nowhere valid to go", and `nearestEnabledIndex` "breaks a tie toward the committed row"; `WheelRest.a11y.chromium.spec.ts` in the TimeInput sheet: "a wheel dragged below the minimum comes to rest on the minimum", "a wheel dragged onto a row inside the bounds commits that row"; `DateInputTouch.test.tsx` "bounds the year wheel to the reachable range" (rows outside the bounds are disabled). | Below the minimum, above the maximum, on another disabled row; opened on a value outside the bounds and rested back on it after a drag; DateInput, TimeInput, and DateTimeInput sheets | A wheel that returns to its committed row, skips the nearest enabled row, breaks a tie away from the committed row, or commits on opening or on a rest back on its committed row fails. | `audit:DateInput/behavior` |
| FR14 | `Wheel.test.tsx` "turns onto a value set while it is shown, as a bound clamping the time after another wheel turned"; `WheelRest.a11y.chromium.spec.ts` in the TimeInput sheet: "a meridiem change past the maximum turns the hour wheel onto it, frame by frame". | A bound clamping the value of a shown wheel after another wheel turned, in DateInput, TimeInput, and DateTimeInput sheets | A wheel that jumps to the new row fails. | `audit:DateInput/behavior` |
| FR15 | `WheelPinchZoom.a11y.chromium.spec.ts` "a pinch over an open picker wheel zooms the page and changes no value"; `DateInputTouch.test.tsx` "leaves a two-finger pinch to the page over the wheels". Evidence gap: no test drives a wheel with trackpad or mouse-wheel streams (the FR15 gap). | A trackpad scroll and its lift; a slow stopped trackpad drag; one and three mouse-wheel notches; a ctrl-scroll over an open wheel | A trackpad scroll that does not follow, a lift that stops dead or coasts at the browser's rate, a notch that turns more or less than one row or coasts, or a ctrl-scroll that turns the wheel fails. | `audit:DateInput/behavior` |
+| FR16 | `DateInput.test.tsx` "Enter submits the form when nothing is typed, and commits typed text without submitting" "Enter on a disabled field does not submit the form" and "Enter on a busy field does not submit the form" | Nothing typed; typed text; disabled; busy (`isLoading`) | An Enter that is prevented with nothing typed, or that submits before typed text commits, fails. | — |
| Theming anatomy | `DateInput.test.tsx` clear-icon and calendar-toggle icon theme-target cases; `themingTargets.test.ts`; `scripts/check-knowledge.mjs` | Toggle, clear glyph, disabled root | A missing or moved target, or a stale anatomy mapping, fails. | `audit:DateInput/theming` |
## Current-state impact
diff --git a/docs/specs/components/DateTimeInput/DateTimeInput.spec.md b/docs/specs/components/DateTimeInput/DateTimeInput.spec.md
index 8bcc53f8f7..acb8b32f9f 100644
--- a/docs/specs/components/DateTimeInput/DateTimeInput.spec.md
+++ b/docs/specs/components/DateTimeInput/DateTimeInput.spec.md
@@ -109,17 +109,18 @@ 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. 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 |
+| 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 |
+| FR10 | Enter in the date segment's text input commits typed text that has not been committed and is then held back, so a form never submits the value from before the commit. With no typed text pending, Enter is not prevented, so a form submits as it does from any text field, except on a disabled or busy field, where Enter does nothing (`spec:AST-085` FR2). |
### Allowed variation
@@ -233,15 +234,16 @@ 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`; `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` |
+| 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` |
+| FR10 | `DateTimeInput.test.tsx` "Enter in the date segment submits the form when nothing is typed, and commits typed text without submitting" "Enter on a disabled field does not submit the form" and "Enter on a busy field does not submit the form" | Nothing typed; typed text; disabled; busy (`isLoading`) | An Enter that is prevented with nothing typed, or that submits before typed text commits, fails. | — |
+| 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/DateInput/DateInput.fr10.test.tsx b/packages/core/src/DateInput/DateInput.fr10.test.tsx
index bc54a77593..aab9041489 100644
--- a/packages/core/src/DateInput/DateInput.fr10.test.tsx
+++ b/packages/core/src/DateInput/DateInput.fr10.test.tsx
@@ -253,9 +253,10 @@ describe('DateInput FR10 handler composition', () => {
}
/>,
);
- fireEvent.keyDown(screen.getByRole('combobox', {name: 'Due'}), {
- key: 'Enter',
- });
+ const input = screen.getByRole('combobox', {name: 'Due'});
+ // Typed text makes Enter a key the field consumes (it commits the text).
+ fireEvent.change(input, {target: {value: '2026-02-03'}});
+ fireEvent.keyDown(input, {key: 'Enter'});
expect(seen).toEqual([{key: 'Enter', defaultPrevented: true}]);
});
diff --git a/packages/core/src/DateInput/DateInput.test.tsx b/packages/core/src/DateInput/DateInput.test.tsx
index 77702f12d3..2cb47c8063 100644
--- a/packages/core/src/DateInput/DateInput.test.tsx
+++ b/packages/core/src/DateInput/DateInput.test.tsx
@@ -421,6 +421,65 @@ describe('DateInput', () => {
expect(input).toHaveAttribute('aria-expanded', 'true');
});
+ it('Enter on a busy field does not submit the form', async () => {
+ const user = userEvent.setup();
+ const onSubmit = vi.fn((e: React.FormEvent) => e.preventDefault());
+ render(
+ <form onSubmit={onSubmit}>
+ <DateInput
+ label="Start date"
+ value="2026-01-12"
+ onChange={() => {}}
+ isLoading
+ />
+ <button type="submit">Save</button>
+ </form>,
+ );
+ screen.getAllByRole('combobox')[0].focus();
+ await user.keyboard('{Enter}');
+ expect(onSubmit).not.toHaveBeenCalled();
+ });
+
+ it('Enter on a disabled field does not submit the form', async () => {
+ const user = userEvent.setup();
+ const onSubmit = vi.fn((e: React.FormEvent) => e.preventDefault());
+ render(
+ <form onSubmit={onSubmit}>
+ <DateInput
+ label="Start date"
+ value="2026-01-12"
+ onChange={() => {}}
+ isDisabled
+ />
+ <button type="submit">Save</button>
+ </form>,
+ );
+ screen.getAllByRole('combobox')[0].focus();
+ await user.keyboard('{Enter}');
+ expect(onSubmit).not.toHaveBeenCalled();
+ });
+
+ it('Enter submits the form when nothing is typed, and commits typed text without submitting', async () => {
+ const user = userEvent.setup();
+ const onSubmit = vi.fn((e: React.FormEvent) => e.preventDefault());
+ const onChange = vi.fn();
+ render(
+ <form onSubmit={onSubmit}>
+ <DateInput label="Start date" value="2026-01-12" onChange={onChange} />
+ <button type="submit">Search</button>
+ </form>,
+ );
+ const input = screen.getByRole('combobox');
+ input.focus();
+ await user.keyboard('{Enter}');
+ expect(onSubmit).toHaveBeenCalledTimes(1);
+ await user.clear(input);
+ await user.type(input, '2026-02-03');
+ await user.keyboard('{Enter}');
+ expect(onChange).toHaveBeenLastCalledWith('2026-02-03');
+ expect(onSubmit).toHaveBeenCalledTimes(1);
+ });
+
describe('press inside and outside the open calendar', () => {
function press(target: Element) {
fireEvent.pointerDown(target, {composed: true});
diff --git a/packages/core/src/DateInput/DateInput.tsx b/packages/core/src/DateInput/DateInput.tsx
index 7dbd43af93..5ddccca198 100644
--- a/packages/core/src/DateInput/DateInput.tsx
+++ b/packages/core/src/DateInput/DateInput.tsx
@@ -884,12 +884,18 @@ function PointerDateField({
if (!isEffectivelyDisabled) {
popover.show({skipAutoFocus: true});
}
- } else if (e.key === 'Enter') {
+ } else if (
+ e.key === 'Enter' &&
+ (pendingInput !== null || isEffectivelyDisabled)
+ ) {
+ // Typed text holds Enter back, or a form would submit the value from
+ // before the commit. A disabled or busy field must not submit its
+ // form either. Otherwise Enter keeps its default, as in any text field.
e.preventDefault();
commitPendingInput();
}
},
- [popover, commitPendingInput, isEffectivelyDisabled],
+ [popover, commitPendingInput, isEffectivelyDisabled, pendingInput],
);
const inputWrapper = (
diff --git a/packages/core/src/DateTimeInput/DateTimeInput.fr10.test.tsx b/packages/core/src/DateTimeInput/DateTimeInput.fr10.test.tsx
index 9793e2e84b..a0b86e4770 100644
--- a/packages/core/src/DateTimeInput/DateTimeInput.fr10.test.tsx
+++ b/packages/core/src/DateTimeInput/DateTimeInput.fr10.test.tsx
@@ -295,9 +295,10 @@ describe('DateTimeInput FR10 handler composition', () => {
}
/>,
);
- fireEvent.keyDown(screen.getByRole('combobox', {name: 'Due'}), {
- key: 'Enter',
- });
+ const input = screen.getByRole('combobox', {name: 'Due'});
+ // Typed text makes Enter a key the field consumes (it commits the text).
+ fireEvent.change(input, {target: {value: '2026-02-03'}});
+ fireEvent.keyDown(input, {key: 'Enter'});
expect(seen).toEqual([{key: 'Enter', defaultPrevented: true}]);
});
diff --git a/packages/core/src/DateTimeInput/DateTimeInput.test.tsx b/packages/core/src/DateTimeInput/DateTimeInput.test.tsx
index bc000b3d85..70fee92db0 100644
--- a/packages/core/src/DateTimeInput/DateTimeInput.test.tsx
+++ b/packages/core/src/DateTimeInput/DateTimeInput.test.tsx
@@ -63,6 +63,69 @@ function expectResponsiveProbeClasses(
}
describe('DateTimeInput', () => {
+ it('Enter on a busy field does not submit the form', async () => {
+ const user = userEvent.setup();
+ const onSubmit = vi.fn((e: React.FormEvent) => e.preventDefault());
+ render(
+ <form onSubmit={onSubmit}>
+ <DateTimeInput
+ label="Starts"
+ value={'2026-01-12T09:00' as ISODateTimeString}
+ onChange={() => {}}
+ isLoading
+ />
+ <button type="submit">Save</button>
+ </form>,
+ );
+ screen.getAllByRole('combobox')[0].focus();
+ await user.keyboard('{Enter}');
+ expect(onSubmit).not.toHaveBeenCalled();
+ });
+
+ it('Enter on a disabled field does not submit the form', async () => {
+ const user = userEvent.setup();
+ const onSubmit = vi.fn((e: React.FormEvent) => e.preventDefault());
+ render(
+ <form onSubmit={onSubmit}>
+ <DateTimeInput
+ label="Starts"
+ value={'2026-01-12T09:00' as ISODateTimeString}
+ onChange={() => {}}
+ isDisabled
+ />
+ <button type="submit">Save</button>
+ </form>,
+ );
+ screen.getAllByRole('combobox')[0].focus();
+ await user.keyboard('{Enter}');
+ expect(onSubmit).not.toHaveBeenCalled();
+ });
+
+ it('Enter in the date segment submits the form when nothing is typed, and commits typed text without submitting', async () => {
+ const user = userEvent.setup();
+ const onSubmit = vi.fn((e: React.FormEvent) => e.preventDefault());
+ const onChange = vi.fn();
+ render(
+ <form onSubmit={onSubmit}>
+ <DateTimeInput
+ label="Starts"
+ value={'2026-01-12T09:00' as ISODateTimeString}
+ onChange={onChange}
+ />
+ <button type="submit">Save</button>
+ </form>,
+ );
+ const dateInput = screen.getAllByRole('combobox')[0];
+ dateInput.focus();
+ await user.keyboard('{Enter}');
+ expect(onSubmit).toHaveBeenCalledTimes(1);
+ await user.clear(dateInput);
+ await user.type(dateInput, '2026-02-03');
+ await user.keyboard('{Enter}');
+ expect(onChange).toHaveBeenLastCalledWith('2026-02-03T09:00');
+ expect(onSubmit).toHaveBeenCalledTimes(1);
+ });
+
it('renders with label', () => {
render(<DateTimeInput label="Meeting time" onChange={() => {}} />);
expect(screen.getByLabelText('Meeting time')).toBeInTheDocument();
diff --git a/packages/core/src/DateTimeInput/DateTimeInput.tsx b/packages/core/src/DateTimeInput/DateTimeInput.tsx
index d62290a5da..909c04ff75 100644
--- a/packages/core/src/DateTimeInput/DateTimeInput.tsx
+++ b/packages/core/src/DateTimeInput/DateTimeInput.tsx
@@ -1143,12 +1143,18 @@ function PointerDateTimeField({
if (!isEffectivelyDisabled) {
popover.show({skipAutoFocus: true});
}
- } else if (e.key === 'Enter') {
+ } else if (
+ e.key === 'Enter' &&
+ (datePendingInput !== null || isEffectivelyDisabled)
+ ) {
+ // Typed text holds Enter back, or a form would submit the value from
+ // before the commit. A disabled or busy field must not submit its
+ // form either. Otherwise Enter keeps its default, as in any text field.
e.preventDefault();
commitDatePendingInput();
}
},
- [popover, commitDatePendingInput, isEffectivelyDisabled],
+ [popover, commitDatePendingInput, isEffectivelyDisabled, datePendingInput],
);
// --- Time-option popover (#2727) ---