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

SideNav - Conditionally set aria-labelledby #2788

Merged
merged 1 commit into from
Mar 27, 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
5 changes: 5 additions & 0 deletions .changeset/dry-buses-eat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hashicorp/design-system-components": patch
---

`SideNav` - Conditionally set `aria-labelledby` attribute for toggle button based on if `@ariaLabel` argument is provided.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
{{! template-lint-enable no-invalid-interactive}}
<Hds::SideNav::ToggleButton
aria-label={{this.ariaLabel}}
aria-labelledby="hds-side-nav-header"
aria-labelledby={{unless this.ariaLabel "hds-side-nav-header"}}
aria-expanded={{if this.isMinimized "false" "true"}}
@icon={{if this.isMinimized "chevrons-right" "chevrons-left"}}
{{on "click" this.toggleMinimizedStatus}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,28 @@ module('Integration | Component | hds/side-nav/index', function (hooks) {

// COLLAPSIBLE

test('if the @ariaLabel argument is not provided the default aria-labelledby value is set on the toggle button', async function (assert) {
await render(
hbs`<Hds::SideNav @isCollapsible={{true}} id="test-side-nav" />`
);
assert
.dom('.hds-side-nav__toggle-button')
.hasAttribute('aria-labelledby', 'hds-side-nav-header');
assert.dom('.hds-side-nav__toggle-button').hasNoAttribute('aria-label');
});

test('if the @ariaLabel argument is provided the label value is set on the toggle button', async function (assert) {
await render(
hbs`<Hds::SideNav @isCollapsible={{true}} id="test-side-nav" @ariaLabel="Test"/>`
);
assert
.dom('.hds-side-nav__toggle-button')
.hasNoAttribute('aria-labelledby');
assert
.dom('.hds-side-nav__toggle-button')
.hasAttribute('aria-label', 'Test');
});

test('it responds to different events to toggle between "non-minimized" (by default) and "mimimized" states', async function (assert) {
await render(
hbs`<Hds::SideNav @isCollapsible={{true}} id="test-side-nav" />`
Expand Down