Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions packages/react/src/components/DatePicker/DatePicker-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,32 @@ describe('Single date picker', () => {
expect(document.body).toHaveFocus();
expect(onClose).toHaveBeenCalledTimes(2);
});

it('should keep native tab navigation when `readOnly` is true', async () => {
render(
<>
<DatePicker datePickerType="single" readOnly>
<DatePickerInput id="readonly-input-id" labelText="Read only input" />
</DatePicker>
<button data-testid="next-focus-target" type="button">
Next focus target
</button>
</>
);

const dateInput = screen.getByLabelText('Read only input');
const nextFocusTarget = screen.getByTestId('next-focus-target');
const calendar = screen.getByRole('application');

expect(calendar).not.toHaveClass('open');
expect(document.body).toHaveFocus();
await userEvent.tab();
expect(dateInput).toHaveFocus();
expect(calendar).not.toHaveClass('open');
await userEvent.tab();
expect(nextFocusTarget).toHaveFocus();
expect(calendar).not.toHaveClass('open');
});
});

describe('Range date picker', () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/react/src/components/DatePicker/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,8 @@ const DatePicker = forwardRef<HTMLDivElement, DatePickerProps>((props, ref) => {
calendarRef.current = calendar;

const handleInputFieldKeyDown = (event: KeyboardEvent) => {
if (readOnly && match(event, keys.Tab)) return;

const {
calendarContainer,
selectedDateElem: fpSelectedDateElem,
Expand Down
Loading