An open source design system that's fully customizable and agent ready
TypeScript
fix(core): open DateTimeInput calendar with ArrowDown from the keyboard (#3991)
Baraa Hamodi0d9c07706448
diff --git a/.changeset/datetimeinput-arrowdown-open.md b/.changeset/datetimeinput-arrowdown-open.mdnew file mode 100644index 0000000000..56b59d17d2--- /dev/null+++ b/.changeset/datetimeinput-arrowdown-open.md@@ -0,0 +1,6 @@+---+'@astryxdesign/core': patch+---++[fix] DateTimeInput: ArrowDown (and Alt+ArrowDown) in the date field now opens the calendar popover from the keyboard, matching DateInput and the advertised combobox pattern.+@bhamodidiff --git a/packages/core/src/DateTimeInput/DateTimeInput.test.tsx b/packages/core/src/DateTimeInput/DateTimeInput.test.tsxindex 0c2bc898c9..3ebc0aae43 100644--- a/packages/core/src/DateTimeInput/DateTimeInput.test.tsx+++ b/packages/core/src/DateTimeInput/DateTimeInput.test.tsx@@ -185,6 +185,41 @@ describe('DateTimeInput', () => {);});+ it('opens the calendar popover on ArrowDown (keyboard, forms-13)', () => {+ render(<DateTimeInput label="Meeting" onChange={() => {}} />);+ const input = screen.getByRole('combobox');+ input.focus();+ expect(input).toHaveAttribute('aria-expanded', 'false');+ fireEvent.keyDown(input, {key: 'ArrowDown'});+ expect(input).toHaveAttribute('aria-expanded', 'true');+ // skipAutoFocus keeps focus in the input, per the APG date-picker pattern+ expect(input).toHaveFocus();+ });++ it('opens the calendar popover on Alt+ArrowDown (keyboard, forms-13)', () => {+ render(<DateTimeInput label="Meeting" onChange={() => {}} />);+ const input = screen.getByRole('combobox');+ fireEvent.keyDown(input, {key: 'ArrowDown', altKey: true});+ expect(input).toHaveAttribute('aria-expanded', 'true');+ });++ it('does not open on ArrowDown when disabled', () => {+ render(<DateTimeInput label="Meeting" isDisabled onChange={() => {}} />);+ const input = screen.getByRole('combobox');+ fireEvent.keyDown(input, {key: 'ArrowDown'});+ expect(input).toHaveAttribute('aria-expanded', 'false');+ });++ it('does not re-trigger on ArrowDown when the calendar is already open', () => {+ render(<DateTimeInput label="Meeting" onChange={() => {}} />);+ const input = screen.getByRole('combobox');+ fireEvent.keyDown(input, {key: 'ArrowDown'});+ expect(input).toHaveAttribute('aria-expanded', 'true');+ // A second ArrowDown is a no-op: the calendar stays open+ fireEvent.keyDown(input, {key: 'ArrowDown'});+ expect(input).toHaveAttribute('aria-expanded', 'true');+ });+it('calendar button is focusable and clickable', () => {render(<DateTimeInput label="Meeting" onChange={() => {}} />);const button = getButton('Open calendar');diff --git a/packages/core/src/DateTimeInput/DateTimeInput.tsx b/packages/core/src/DateTimeInput/DateTimeInput.tsxindex af2fd3b0f8..38cdc080ba 100644--- a/packages/core/src/DateTimeInput/DateTimeInput.tsx+++ b/packages/core/src/DateTimeInput/DateTimeInput.tsx@@ -719,12 +719,22 @@ export function DateTimeInput({if (e.key === 'Escape' && popover.isOpen) {e.preventDefault();popover.hide();+ } else if (+ (e.key === 'ArrowDown' || (e.altKey && e.key === 'ArrowDown')) &&+ !popover.isOpen+ ) {+ // APG combobox: ArrowDown (and Alt+ArrowDown) opens the calendar+ // popover from the keyboard, keeping focus in the input (forms-13).+ e.preventDefault();+ if (!isEffectivelyDisabled) {+ popover.show({skipAutoFocus: true});+ }} else if (e.key === 'Enter') {e.preventDefault();commitDatePendingInput();}},- [popover, commitDatePendingInput],+ [popover, commitDatePendingInput, isEffectivelyDisabled],);// --- Time handlers ---