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

Tab order is not in visual order when captionLayout is "dropdown" #2629

Open
mrdaniellewis opened this issue Dec 18, 2024 · 1 comment
Open
Assignees
Labels
accessibility bug Bug or Bug fixes

Comments

@mrdaniellewis
Copy link

To reproduce

import { DayPicker } from "react-day-picker";
import "react-day-picker/style.css";

export default function App() {
  return <DayPicker mode="single" captionLayout="dropdown" />;
}

CodeSandbox: https://codesandbox.io/p/sandbox/daypicker-bug-report-forked-mthnh4

Use tab / shift + Tab to move though the focusable elements.

Actual Behaviour

The tabbing order does not match visual order

Tab order: Previous month, next month, Month dropdown, Year dropdown, calendar grid
Visual order: Month dropdown, Year dropdown, Previous month, next month, calendar grid

That is the previous and next months are focused before the month and year dropdowns; however visually the month and year dropdowns are displayed before the previous and next buttons.

This wasn't the case with version 8.

Possible failure of https://www.w3.org/TR/WCAG22/#focus-order. It feels confusing if navigating with a keyboard.

Expected Behaviour

The tabbing order should match the visual order:

Workaround

Overriding the <Months> component with this monstrosity (and modifying the css) can be used to workaround this issue.

function Months({ className, children }) {
  const [
    nav,
    {
      props: {
        children: [caption, grid],
      },
    },
  ] = Children.toArray(children);
  return (
    <div className={className}>
      {caption}
      {nav}
      {grid}
    </div>
  );
}
@gpbl gpbl self-assigned this Dec 29, 2024
@gpbl
Copy link
Owner

gpbl commented Jan 10, 2025

To address this, we should rewrite the HTML structure of the calendar, which would become a breaking change for our users.

Instead, I'd explore a navLayout prop that could allow to set alternative navigation layouts.

@gpbl gpbl added the bug Bug or Bug fixes label Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accessibility bug Bug or Bug fixes
Projects
None yet
Development

No branches or pull requests

2 participants