Skip to content

MudTabs: Improve accessibility#11581

Merged
danielchalmers merged 22 commits intoMudBlazor:devfrom
nccadman19:fix/accessible-tabs
Aug 2, 2025
Merged

MudTabs: Improve accessibility#11581
danielchalmers merged 22 commits intoMudBlazor:devfrom
nccadman19:fix/accessible-tabs

Conversation

@nccadman19
Copy link
Contributor

@nccadman19 nccadman19 commented Jul 2, 2025

fix(MudTabs): improve accessibility for keyboard interaction

  • Makes tabs focusable using Arrow keys and responsive to Enter/Space keys
  • Prevents key navigation into disabled tab content
  • Aligns behaviour with accessibility standards (WCAG)
  • Adds proper ARIA attributes for screen reader support
  • Identify.Create used for the componentId
  • Label Guidance

Tested locally in MudBlazor.Docs to confirm behaviour across input methods.

Description

This PR enhances keyboard accessibility in MudTabs by implementing proper keyboard navigation and ARIA support. Previously, the tabs component lacked proper keyboard interaction patterns, making it difficult for keyboard and screen reader users to navigate between tabs effectively.

Changes include:

  • Keyboard Navigation: Added support for arrow key navigation (Left/Right for horizontal tabs, Up/Down for vertical tabs)
  • Activation Keys: Tabs can now be activated using Enter and Space keys
  • Focus Management: Proper tab index management ensures only the active tab is in the tab order
  • Disabled Tab Handling: Keyboard navigation correctly skips disabled tabs and wraps around to enabled tabs
  • ARIA Support: Added proper role="tab", role="tablist", role="tabpanel", and aria-selected attributes
  • Accessibility Compliance: Follows W3C WAI-ARIA authoring practices for tab components

New Changes

  • Made TabsDragAndDrop_With_FiresOnItemDroppedAsync() an async task to resolve error
  • Tabindex removed from
    aria-controls
  • Role, id, aria-selected, tabindex and onkeydown added to mudtabs
  • Indexing on the tabpanel updated to the fieldid
  • Public strings made internal
  • Space tests added to tabtests, keeptabsnotalive test updated to pass
  • Updated gettablistid to be created oninitialized to avoid creating a new string object every time it's called
  • Implemented the Delete shortcut for deletable tabs in muddynamictabs
  • Added key interceptor to tab bar to prevent page scroll on space buttons

How Has This Been Tested?

Tested locally by running the MudBlazor docs site using the edited source code:

  • Keyboard Navigation: Verified arrow key navigation works in both horizontal and vertical tab orientations
  • Activation: Confirmed tabs activate properly with Enter and Space keys
  • Focus Management: Tested that focus moves correctly between enabled tabs and skips disabled ones
  • Wrapping: Verified navigation wraps from first to last tab and vice versa
  • Screen Reader: Tested with screen reader to confirm ARIA attributes work correctly
  • Unit Tests: Added test coverage for keyboard interactions

Type of Changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation (fix or improvement to the website or code docs)

Checklist

  • The PR is submitted to the correct branch (dev).
  • My code follows the code style of this project.
  • I've added relevant tests (manual/visual verification in Docs).

Related Issues

- added role="tab", role="tabpanel" and role="tablist" attributes
- implemented keyboard navigation (ArrowLeft, ArrowRight, Enter, Space) with manual activation
- added tabindex handling for correct focus behaviour
- added unit tests to validate keyboard navigation, attributes, and focus behaviour
@github-actions github-actions bot added the bug Unexpected behavior or functionality not working as intended label Jul 2, 2025
@codecov
Copy link

codecov bot commented Jul 2, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.30%. Comparing base (b9cffa9) to head (9ba3dc2).
⚠️ Report is 2 commits behind head on dev.

Additional details and impacted files
@@           Coverage Diff           @@
##              dev   #11581   +/-   ##
=======================================
  Coverage   91.30%   91.30%           
=======================================
  Files         466      466           
  Lines       14709    14717    +8     
  Branches     2869     2869           
=======================================
+ Hits        13430    13438    +8     
  Misses        636      636           
  Partials      643      643           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@danielchalmers danielchalmers added the accessibility Accessibility concerns (ARIA, keyboard, focus, screen readers, contrast) label Jul 3, 2025
Copy link
Member

@danielchalmers danielchalmers left a comment

Choose a reason for hiding this comment

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

I need to test locally but always love to see more accessibility!

There's a number of formatting diffs, could you see if you can revert them so it's easier to review the real changes?

This comment was marked as outdated.

- Add stable ID generation for tabs and panels
- Implement aria-controls and aria-labelledby attributes
- Use panel index for indentification
- Ensure bidirectional accessibility relationship between tabs and panels
Copy link
Contributor

@versile2 versile2 left a comment

Choose a reason for hiding this comment

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

Apart from the MudTabPanel needing the class/style/attributes this feels ready to go.

Copy link
Member

@igotinfected igotinfected left a comment

Choose a reason for hiding this comment

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

Appreciate your accessibility contribution!!

Added a few comments and tested the changes locally, some feedback:

  • in the "scrollable list" example the scroll icons aren't updated when hitting the last page/item ("go right" button should disappear, "go left" button should appear) and sometimes the view doesn't scroll with the focus, such that the focused tab is out of view (local WASM docs test URL)
  • in the "visibility" example, toggling the visibility of the second tab breaks keyboard navigation (switching focus between the visible tabs doesn't work as expected) (local WASM docs test URL)
  • if you're up for it you could also implement the Delete shortcut for deletable tabs in this local WASM docs example) for example
  • in the "simple tabs" example the tab wrapper has an aria-labelledby that points to an element that doesn't exist, I believe this is something that should be user controlled if they provide a label for the tab component
  • pressing Space to activate a tab makes the page jump, you can refer to MudCheckBox's implementation for how to fix that

Don't necessarily think any of these are blocking for the PR though!

aria-controls, role, id, aria-selected, tabindex and onkeydown added to mudtabs
indexing on the tabpanel updated to the fieldid
public string made internal
space tests added to tabtests, keeptabsnotalive test updated to pass
…reating a new string object every time it's called
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accessibility Accessibility concerns (ARIA, keyboard, focus, screen readers, contrast) bug Unexpected behavior or functionality not working as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants