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

Fix aria-expanded state for sidenav and expansion list entries #11812

Merged
merged 1 commit into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/_includes/expansion-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<div class="expansion-panel">
<a class="{{class}} collapsible"
data-toggle="collapse"
data-target="#{{id}}"
href="#{{id}}"
role="button"
aria-expanded="{{expanded}}"
Expand All @@ -32,7 +33,7 @@
{%- if item.data.iconPath %}
<img src="{{item.data.iconPath}}" alt="An icon showing a generic application." />
{%- else %}
<img src="/assets/images/docs/app-architecture/design-patterns/kv-store-icon.svg" alt="A ivon showing a generic application." />
<img src="/assets/images/docs/app-architecture/design-patterns/kv-store-icon.svg" alt="A icon showing a generic application." />
{%- endif %}

</div>
Expand Down
5 changes: 5 additions & 0 deletions src/_sass/components/_expansion-list.scss
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
}

.expansion-panel-body {
display: none;
margin: auto;
width: 90%;
border-top: .05rem solid rgba(0, 0, 0, 0.125);
Expand All @@ -125,6 +126,10 @@
margin-top: 1.5rem;
border-top: .05rem solid rgba(0, 0, 0, 0.125);
}

&.show {
display: block;
}
}

> :last-child {
Expand Down
8 changes: 4 additions & 4 deletions src/_sass/components/_sidebar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@

+ ul {
display: none;

&.show {
display: block;
}
}

&:hover {
Expand All @@ -134,10 +138,6 @@
.expander {
transform: rotate(180deg);
}

+ ul {
display: block;
}
}

&.active {
Expand Down
24 changes: 21 additions & 3 deletions src/content/assets/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,29 @@ function setupSidenavInteractivity() {
}
}
});
}

// Set up collapse and expand for sidenav buttons.
const toggles = document.querySelectorAll('.nav-link.collapsible');
function setupCollapsibleElements() {
const toggles = document.querySelectorAll('[data-toggle="collapse"]');
toggles.forEach(function (toggle) {
const targetSelector = toggle.getAttribute('data-target');
if (!targetSelector) return;
const target = document.querySelector(targetSelector);
if (!target) return;

toggle.addEventListener('click', (e) => {
toggle.classList.toggle('collapsed');
if (toggle.classList.contains('collapsed')) {
toggle.classList.remove('collapsed');
toggle.ariaExpanded = 'true';

target.classList.add('show');
} else {
toggle.classList.add('collapsed');
toggle.ariaExpanded = 'false';

target.classList.remove('show');
}

e.preventDefault();
});
});
Expand Down Expand Up @@ -433,6 +450,7 @@ function setupSite() {

setupToc();
setupPlatformKeys();
setupCollapsibleElements();
setupFeedback();
}

Expand Down