Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set tabIndex to 0 when day is focused #1601

Merged
merged 2 commits into from Nov 6, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -296,6 +296,20 @@ describe('when the day is target of focus but outside', () => {
});
});

describe('when the day is focused', () => {
const date = today;
const focusContext: FocusContextValue = {
...mockedFocusContext,
focusedDay: date
};
beforeEach(() => {
setup(date, date, {}, { focus: focusContext });
});
test('the button should have tabIndex 0', () => {
expect(result.current.buttonProps.tabIndex).toBe(0);
});
});

describe('when the day is disabled', () => {
const date = today;
const dayPickerProps = {
Expand Down
Expand Up @@ -104,12 +104,15 @@ export function useDayRender(
isSameDay(focusContext.focusTarget, day) &&
!activeModifiers.outside;

const isFocused =
focusContext.focusedDay && isSameDay(focusContext.focusedDay, day);

const buttonProps = {
...divProps,
disabled: activeModifiers.disabled,
['aria-pressed']: activeModifiers.selected,
['aria-label']: ariaLabel,
tabIndex: isFocusTarget ? 0 : -1,
tabIndex: isFocused || isFocusTarget ? 0 : -1,
...eventHandlers
};

Expand Down