Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

nccadman19
Copy link
Contributor

@nccadman19 nccadman19 commented Jun 20, 2025

fix(MudExpansionPanel): improve accessibility for keyboard and mouse interaction

  • Makes header focusable and responsive to Enter/Space keys
  • Prevents tab navigation into collapsed panel content
  • Aligns behavior with accessibility standards (WCAG)

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

Description

This PR enhances accessibility in MudExpansionPanel when using custom TitleContent. The default behavior does not support keyboard interaction or proper focus handling, particularly when the panel is collapsed. This results in users being unable to toggle the panel via keyboard or inadvertently tabbing into visually hidden content.

Changes include:

  • Making the header focusable when custom content is used
  • Allowing toggling via Enter and Space
  • Preventing tab order from entering content when collapsed
  • Preserving click behavior on both container and text elements

These changes improve usability for keyboard and screen reader users and follow accessibility best practices.

How Has This Been Tested?

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

  • Verified focus behavior and keyboard toggling with Tab, Enter, and Space
  • Confirmed tab order skips collapsed content
  • Manually tested pointer interactions with both whitespace and inner text
  • No console errors and no impact to existing styles or features

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

fix(MudExpansionPanel): improve accessibility for keyboard and mouse interaction

- Makes header focusable and responsive to Enter/Space keys
- Prevents tab navigation into collapsed panel content
- Aligns behavior with accessibility standards (WCAG)

Tested locally in MudBlazor.Docs to confirm behaviour across input methods.
@github-actions github-actions bot added the bug Unexpected behavior or functionality not working as intended label Jun 20, 2025
Copy link

codecov bot commented Jun 20, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.20%. Comparing base (e9baca0) to head (c4361ed).
Report is 7 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev   #11531      +/-   ##
==========================================
+ Coverage   91.18%   91.20%   +0.01%     
==========================================
  Files         466      466              
  Lines       14652    14687      +35     
  Branches     2847     2855       +8     
==========================================
+ Hits        13361    13395      +34     
  Misses        646      646              
- Partials      645      646       +1     

☔ 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.

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.

Keyboard accessibility is always needed! Just some things to tweak

@danielchalmers danielchalmers changed the title BugFix: Mud Expansion Panel MudExpansionPanel: Improve accessibility for keyboard and mouse interaction Jun 21, 2025
@danielchalmers danielchalmers added accessibility Accessibility concerns (ARIA, keyboard, focus, screen readers, contrast) and removed bug Unexpected behavior or functionality not working as intended labels Jun 21, 2025
…d optional content removal

- Prevented focus and keyboard interaction on disabled panel headers by conditionally omitting tabindex
- Introduced `RemoveContentOnCollapse` parameter to optionally remove panel content from the DOM when collapsed
- Default behaviour retains content to preserve component state and avoid breaking changes
- Added `hidden` and `aria-hidden` attributes to hide content from accessibility tree while keeping it mounted
Aria hidden removed
Flipped bool similar to MudTabs
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.

Awesome! Could you add some HandleKeyDownAsync and KeepContentAlive tests to finish it off? (also small thing but its back to tabs in the razor)

@danielchalmers danielchalmers changed the title MudExpansionPanel: Improve accessibility for keyboard and mouse interaction MudExpansionPanel: Add toggle keyboard hotkeys, Add ability to remove content from DOM Jun 25, 2025
…ssibility features

- Add keyboard navigation tests for Enter/Space key toggling
- Test accessibility behavior with hidden attribute for collapsed content
- Add HandleKeyDownAsync tests for disabled state and non-trigger keys
- Add KeepContentAlive tests for content rendering lifecycle
- Verify proper interaction between KeepContentAlive and accessibility states

MudExpansionPanel updated to spaces
Copy link

@nccadman19
Copy link
Contributor Author

Awesome! Could you add some HandleKeyDownAsync and KeepContentAlive tests to finish it off? (also small thing but its back to tabs in the razor)

Hey, tests added! Hope they're ok, and updated the files back to spaces

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.

Great work!

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)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expansion Panel Tabbing
3 participants