An open source design system that's fully customizable and agent ready
TypeScript
fix(DateInput): block changes from disabled open pickers (#8813)
zakelstorme770c8296f9c
diff --git a/.changeset/ast-085-dateinput.md b/.changeset/ast-085-dateinput.mdnew file mode 100644index 0000000000..8de849488b--- /dev/null+++ b/.changeset/ast-085-dateinput.md@@ -0,0 +1,6 @@+---+'@astryxdesign/core': patch+---++[fix] DateInput ignores selections from an already-open disabled picker and blocks Reset's value change and month navigation while disabled, without dismissing the picker or moving focus.+@korkt-kimdiff --git a/packages/core/src/DateInput/DateInput.test.tsx b/packages/core/src/DateInput/DateInput.test.tsxindex cb2f7e6627..9476264a32 100644--- a/packages/core/src/DateInput/DateInput.test.tsx+++ b/packages/core/src/DateInput/DateInput.test.tsx@@ -21,7 +21,7 @@ import {} from '@testing-library/react';import userEvent from '@testing-library/user-event';import {getButton, queryButton} from '../__tests__/fastRoleQueries';-import {DateInput} from './DateInput';+import {DateInput, type DateInputProps} from './DateInput';import {Icon} from '../Icon';import {InputGroup} from '../InputGroup';import {InputGroupText} from '../InputGroup/InputGroupText';@@ -570,6 +570,67 @@ describe('DateInput', () => {);});+ it('blocks selection in an open picker after the field becomes disabled', async () => {+ const user = userEvent.setup();+ const props = {+ label: 'Date',+ value: '2026-10-15',+ presentation: 'popover',+ onChange: vi.fn(),+ changeAction: vi.fn(),+ } satisfies DateInputProps;+ const {rerender} = render(<DateInput {...props} />);+ const input = screen.getByRole('combobox');+ act(() => input.focus());+ await user.keyboard('{ArrowDown}');+ const day = getButton(/October 16, 2026/);+ act(() => day.focus());++ rerender(<DateInput {...props} isDisabled />);+ expect(day).toHaveFocus();+ await user.click(day);+ await user.keyboard(' ');++ rerender(+ <DateInput+ {...props}+ isDisabled+ disabledMessage="Scheduling is locked"+ />,+ );+ expect(day).toHaveFocus();+ await user.keyboard('{Enter}');+ expect(props.onChange).not.toHaveBeenCalled();+ expect(props.changeAction).not.toHaveBeenCalled();+ expect(input).toHaveValue('October 15, 2026');+ expect(input).toHaveAttribute('aria-expanded', 'true');+ expect(day).toHaveFocus();+ });++ it('dismisses an open picker without committing while loading', async () => {+ const user = userEvent.setup();+ const props = {+ label: 'Date',+ value: '2026-10-15',+ presentation: 'popover',+ onChange: vi.fn(),+ changeAction: vi.fn(),+ } satisfies DateInputProps;+ const {rerender} = render(<DateInput {...props} />);+ await user.click(getButton('Open calendar'));+ const day = getButton(/October 16, 2026/);++ rerender(<DateInput {...props} isLoading />);+ await user.click(day);+ expect(props.onChange).not.toHaveBeenCalled();+ expect(props.changeAction).not.toHaveBeenCalled();+ expect(screen.getByRole('combobox')).toHaveValue('October 15, 2026');+ expect(screen.getByRole('combobox')).toHaveAttribute(+ 'aria-expanded',+ 'false',+ );+ });+// --- Enter key commits typed date ---it('commits typed date and fires onChange on Enter key', () => {diff --git a/packages/core/src/DateInput/DateInput.tsx b/packages/core/src/DateInput/DateInput.tsxindex 1ce9e2107d..72699ae10a 100644--- a/packages/core/src/DateInput/DateInput.tsx+++ b/packages/core/src/DateInput/DateInput.tsx@@ -680,7 +680,7 @@ function PointerDateField({// Unified change handler that fires both onChange and changeActionconst fireChange = useCallback((newValue: ISODateString | undefined) => {- if (isBusy) {+ if (isEffectivelyDisabled) {return;}onChange?.(newValue);@@ -691,7 +691,13 @@ function PointerDateField({});}},- [isBusy, onChange, changeAction, startTransition, setOptimisticValue],+ [+ isEffectivelyDisabled,+ onChange,+ changeAction,+ startTransition,+ setOptimisticValue,+ ],);// Handle clear button click@@ -714,11 +720,16 @@ function PointerDateField({// Handle date selection from calendarconst handleDateSelect = useCallback((selectedDate: ISODateString) => {+ // An already-open calendar can outlive an enabled owner. Reject the+ // whole selection, including dismissal, so its focused day stays put.+ if (isDisabled) {+ return;+ }fireChange(selectedDate);setPendingInput(null);popover.hide();},- [fireChange, popover],+ [isDisabled, fireChange, popover],);// Handle input text change - update immediately if valid and alloweddiff --git a/packages/core/src/DateInput/DateInputTouch.test.tsx b/packages/core/src/DateInput/DateInputTouch.test.tsxindex a241025106..3182c3cae2 100644--- a/packages/core/src/DateInput/DateInputTouch.test.tsx+++ b/packages/core/src/DateInput/DateInputTouch.test.tsx@@ -29,6 +29,7 @@ import {afterEach,} from 'vitest';import {+ act,render,screen,fireEvent,@@ -276,6 +277,81 @@ function weekdayRow(): HTMLElement {return row as HTMLElement;}+describe('DateInput — open-sheet disablement', () => {+ it('blocks selection after the open sheet becomes disabled, retaining value and focus', () => {+ const onChange = vi.fn();+ const changeAction = vi.fn();+ const props = {initial: '2026-02-21' as const, onChange, changeAction};+ withLayout(() => {+ const {rerender} = render(<Controlled {...props} />);+ fireEvent.click(field());+ const day = within(pane('February 2026')).getByRole('button', {+ name: /February 22, 2026/,+ });+ act(() => day.focus());+ rerender(<Controlled {...props} isDisabled />);+ expect(day).toHaveFocus();+ fireEvent.click(day);++ expect(onChange).not.toHaveBeenCalled();+ expect(changeAction).not.toHaveBeenCalled();+ expect(field()).toHaveValue('February 21, 2026');+ expect(field()).toHaveAttribute('aria-expanded', 'true');+ expect(day).toHaveFocus();+ expect(+ document.querySelector('[data-title="month-year"]'),+ ).toHaveTextContent('February 2026');++ rerender(<Controlled {...props} />);+ fireEvent.click(day);+ expect(onChange).toHaveBeenCalledExactlyOnceWith('2026-02-22');+ expect(changeAction).toHaveBeenCalledExactlyOnceWith('2026-02-22');+ expect(field()).toHaveAttribute('aria-expanded', 'true');+ });+ });++ it('blocks disabled reset but preserves busy-only month navigation', () => {+ const onChange = vi.fn();+ const changeAction = vi.fn();+ const props = {initial: '2026-02-21' as const, onChange, changeAction};+ withLayout(() => {+ const {rerender} = render(<Controlled {...props} />);+ fireEvent.click(field());+ const reset = screen.getByRole('button', {name: 'Reset'});+ act(() => reset.focus());+ rerender(<Controlled {...props} isDisabled />);+ expect(reset).toHaveFocus();+ fireEvent.click(reset);++ expect(onChange).not.toHaveBeenCalled();+ expect(changeAction).not.toHaveBeenCalled();+ expect(field()).toHaveValue('February 21, 2026');+ expect(field()).toHaveAttribute('aria-expanded', 'true');+ expect(reset).toHaveFocus();+ expect(+ document.querySelector('[data-title="month-year"]'),+ ).toHaveTextContent('February 2026');++ rerender(<Controlled {...props} isLoading />);+ fireEvent.click(reset);+ expect(onChange).not.toHaveBeenCalled();+ expect(changeAction).not.toHaveBeenCalled();+ expect(field()).toHaveValue('February 21, 2026');+ expect(field()).toHaveAttribute('aria-expanded', 'true');+ expect(reset).toHaveFocus();+ expect(+ document.querySelector('[data-title="month-year"]'),+ ).toHaveTextContent('March 2026');++ rerender(<Controlled {...props} />);+ fireEvent.click(reset);+ expect(onChange).toHaveBeenCalledExactlyOnceWith(undefined);+ expect(changeAction).toHaveBeenCalledExactlyOnceWith(undefined);+ expect(field()).toHaveAttribute('aria-expanded', 'true');+ });+ });+});+// ---------------------------------------------------------------------------// Which surface, and why// ---------------------------------------------------------------------------diff --git a/packages/core/src/DateInput/TouchDateField.tsx b/packages/core/src/DateInput/TouchDateField.tsxindex 372be82caf..18209cb856 100644--- a/packages/core/src/DateInput/TouchDateField.tsx+++ b/packages/core/src/DateInput/TouchDateField.tsx@@ -772,7 +772,7 @@ export function TouchDateField({const fireChange = useCallback((newValue: ISODateString | undefined) => {- if (isBusy) {+ if (isEffectivelyDisabled) {return;}onChange?.(newValue);@@ -783,7 +783,13 @@ export function TouchDateField({});}},- [isBusy, onChange, changeAction, startTransition, setOptimisticValue],+ [+ isEffectivelyDisabled,+ onChange,+ changeAction,+ startTransition,+ setOptimisticValue,+ ],);const openSheet = useCallback(() => {@@ -841,6 +847,11 @@ export function TouchDateField({* value is still cleared either way — that half never depends on the range.*/const handleResetInSheet = useCallback(() => {+ // Disabled: reject the entire reset without closing or moving focus.+ // Busy-only fields keep month navigation; fireChange blocks the clear.+ if (isDisabled) {+ return;+ }fireChange(undefined);const currentMonth = monthIndexOf(today);if (currentMonth < minMonthIndex || currentMonth > maxMonthIndex) {@@ -851,7 +862,7 @@ export function TouchDateField({}setMonthIndex(currentMonth);scrollerHandleRef.current?.scrollToMonth(currentMonth, 'smooth');- }, [fireChange, today, monthIndex, minMonthIndex, maxMonthIndex]);+ }, [isDisabled, fireChange, today, monthIndex, minMonthIndex, maxMonthIndex]);// Selection commits on the tap and leaves the sheet up, so a mistake can be// corrected in place and a nearby date reconsidered without reopening.