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

Add ARIA roles and labelledby to branch dropdown tabs #17172

Merged
merged 4 commits into from
Aug 9, 2023

Conversation

jacortinas
Copy link
Contributor

@jacortinas jacortinas commented Aug 3, 2023

References:

Description

When opening the branches dropdown, focus is automatically shifted to the filter input of the most recently selected tab. This is either the filter input within the "Branches" tab or the "Pull Requests" tab. The issue is that without proper ARIA role and aria-labelledby attributes, screen readers do not announce any context regarding the parent elements of the input currently in focus. This PR fixes that by passing role and labelledBy properties from the branch dropdown down to the child FilterList-ish components.

This could have been solved in other ways by adding parent div elements inside of the BranchesContainer component, that contained the correct role="tabpanel" and aria-labelledby attributes. However, I think there is a benefit to the commonly used FilterList and SectionFilterList components being able to have different ARIA attributes depending on the parent components usage of the properties.

Screenshots

Release notes

Notes: [New] Improve branch dropdown tabs screen reader support

@jacortinas jacortinas self-assigned this Aug 3, 2023
Copy link
Contributor

@tidy-dev tidy-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is working as expected. 💖

This could have been solved in other ways by adding parent div elements inside of the BranchesContainer component, that contained the correct role="tabpanel" and aria-labelledby attributes. However, I think there is a benefit to the commonly used FilterList and SectionFilterList components being able to have different ARIA attributes depending on the parent components usage of the properties.

I think I prefer that solution. Reason being is, in this particular scenario, the list is only contents of the tabpanel, but technically someday we may decide to add more controls to this tab and then this would need refactored. Also, is not a common pattern for a list itself to be a tabpanel nor have a role placed on it's parent container. The list itself may and that is already handled in the list component, but not the container. Another smaller concern is that the addition of props like this makes it seem like it is a reasonable expectation to provide an aria-labelledby to a list container which is only WCAG correct if that div has a role added to it that also requires a label association. In this use case, that is true, but we are opening the props up to any combination of usage.. which could lead a future developer to a mistake since "it can" accept it.

Does that make sense?

Copy link
Contributor

@tidy-dev tidy-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking great! Thank you for that change.

One small nit I promise then we can get it merged.

What do you think about reducing some of the reused logic and have a method like:

private renderSelectedTab() {
    const { selectedTab, repository } = this.props

    const ariaLabelledBy =
      selectedTab === BranchesTab.Branches || !repository.gitHubRepository
        ? 'branches-tab'
        : 'pull-requests-tab'

    return (
      <div
        role="tabpanel"
        aria-labelledby={ariaLabelledBy}
        className="branches-container-panel"
      >
        {this.renderSelectedTabContent()}
      </div>
    )
  }

and rename the current renderSelectedTab to renderSelectedTabContent?

Copy link
Contributor

@tidy-dev tidy-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✨ Thank you again for the change. 🙏 LGTM!

@jacortinas jacortinas merged commit d0e08d1 into development Aug 9, 2023
@jacortinas jacortinas deleted the jc-tab-focus-fix branch August 9, 2023 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants