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

feat(radio, radio-group): Enhance accessibility with arrow key navigation and aria attributes #951

Open
wants to merge 2 commits into
base: next
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions src/components/dialog/bl-dialog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ describe("bl-dialog", () => {
<header>
<bl-button
icon="close"
label="close"
kind="neutral"
size="small"
variant="tertiary"
Expand Down
1 change: 1 addition & 0 deletions src/components/dialog/bl-dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ export default class BlDialog extends LitElement {
? html`<bl-button
@click="${() => this.closeDialog("close-button")}"
icon="close"
label="close"
variant="tertiary"
kind="neutral"
size="small"
Expand Down
2 changes: 2 additions & 0 deletions src/components/drawer/bl-drawer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe("bl-drawer", () => {
<div class="header-buttons">
<bl-button
icon="close"
label="close"
variant="tertiary"
size="small"
kind="neutral"
Expand Down Expand Up @@ -73,6 +74,7 @@ describe("bl-drawer", () => {
></bl-button>
<bl-button
icon="close"
label="close"
variant="tertiary"
size="small"
kind="neutral"
Expand Down
1 change: 1 addition & 0 deletions src/components/drawer/bl-drawer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ export default class BlDrawer extends LitElement {
<bl-button
@click="${this.closeDrawer}"
icon="close"
label="close"
size="small"
variant="tertiary"
kind="neutral"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe("bl-progress-indicator", () => {
<div
class="progress-indicator"
role="progressbar"
aria-label="progress indicator"
aria-valuemax="100"
aria-valuenow="0"
></div>
Expand Down
1 change: 1 addition & 0 deletions src/components/progress-indicator/bl-progress-indicator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export default class BlProgressIndicator extends LitElement {
return html`<div
class="progress-indicator"
role="progressbar"
aria-label="progress indicator"
aria-valuemax="${this._max}"
aria-valuenow="${this._value}"
></div>`;
Expand Down
15 changes: 8 additions & 7 deletions src/components/radio-group/bl-radio-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,18 @@ export default class BlRadioGroup extends FormControlMixin(LitElement) {
// Next option
if (["ArrowDown", "ArrowRight"].includes(event.key)) {
this.focusedOptionIndex++;
if (this.focusedOptionIndex >= this.availableOptions.length) {
this.focusedOptionIndex = 0; // Wrap around to the first option
}
this.availableOptions[this.focusedOptionIndex].select();

// Previous option
} else if (["ArrowUp", "ArrowLeft"].includes(event.key)) {
this.focusedOptionIndex--;
if (this.focusedOptionIndex < 0) {
this.focusedOptionIndex = this.availableOptions.length - 1; // Wrap around to the last option
}
this.availableOptions[this.focusedOptionIndex].select();

// Select option
} else if ([" "].includes(event.key)) {
Expand All @@ -90,17 +98,10 @@ export default class BlRadioGroup extends FormControlMixin(LitElement) {
return;
}

// Don't exceed array indexes
this.focusedOptionIndex = Math.max(
0,
Math.min(this.focusedOptionIndex, this.availableOptions.length - 1)
);

this.availableOptions[this.focusedOptionIndex].focus();

event.preventDefault();
}

connectedCallback(): void {
super.connectedCallback();

Expand Down
2 changes: 1 addition & 1 deletion src/components/radio-group/radio/bl-radio.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe("bl-radio", () => {
`<div
aria-disabled="false"
aria-labelledby="label"
aria-readonly="false"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don’t quite understand why you did this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

aria-readonly property is not supported in Radio Group according to W3C ARIA Radio Group Example

aria-checked="false"
class="wrapper"
role="radio"
>
Expand Down
2 changes: 1 addition & 1 deletion src/components/radio-group/radio/bl-radio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export default class BlRadio extends LitElement {
role="radio"
aria-labelledby="label"
aria-disabled=${this.disabled}
aria-readonly=${this.disabled}
aria-checked=${this.selected}
@blur=${this.blur}
@click=${this.select}
>
Expand Down
Loading