MudExpansionPanel: Add toggle keyboard hotkeys, Add ability to remove content from DOM#11531
Conversation
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.
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. 🚀 New features to boost your workflow:
|
src/MudBlazor/Components/ExpansionPanel/MudExpansionPanel.razor
Outdated
Show resolved
Hide resolved
danielchalmers
left a comment
There was a problem hiding this comment.
Keyboard accessibility is always needed! Just some things to tweak
src/MudBlazor/Components/ExpansionPanel/MudExpansionPanel.razor
Outdated
Show resolved
Hide resolved
src/MudBlazor/Components/ExpansionPanel/MudExpansionPanel.razor
Outdated
Show resolved
Hide resolved
…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
src/MudBlazor/Components/ExpansionPanel/MudExpansionPanel.razor.cs
Outdated
Show resolved
Hide resolved
src/MudBlazor/Components/ExpansionPanel/MudExpansionPanel.razor
Outdated
Show resolved
Hide resolved
src/MudBlazor/Components/ExpansionPanel/MudExpansionPanel.razor
Outdated
Show resolved
Hide resolved
src/MudBlazor/Components/ExpansionPanel/MudExpansionPanel.razor.cs
Outdated
Show resolved
Hide resolved
Aria hidden removed Flipped bool similar to MudTabs
danielchalmers
left a comment
There was a problem hiding this comment.
Awesome! Could you add some HandleKeyDownAsync and KeepContentAlive tests to finish it off? (also small thing but its back to tabs in the razor)
…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
|
Hey, tests added! Hope they're ok, and updated the files back to spaces |



fix(MudExpansionPanel): improve accessibility for keyboard and mouse interaction
Tested locally in MudBlazor.Docs to confirm behaviour across input methods.
Description
This PR enhances accessibility in
MudExpansionPanelwhen using customTitleContent. 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:
EnterandSpaceThese 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:
Tab,Enter, andSpaceType of Changes
Checklist
dev).Related Issues