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(select): accessibility improvement on select and option component #588

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
10 changes: 9 additions & 1 deletion src/components/select/bl-select.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ describe('bl-select', () => {
<fieldset
class="select-input"
tabindex="0"
role="button"
aria-haspopup="listbox"
aria-labelledby="label"
aria-expanded="false"
>
<legend><span></span></legend>
<span class="placeholder"></span>
Expand All @@ -42,7 +46,11 @@ describe('bl-select', () => {
<bl-icon class="dropdown-icon closed" name="arrow_down"></bl-icon>
</div>
</fieldset>
<div class="popover" tabindex="-1">
<div class="popover" tabindex="-1"
role="listbox"
aria-multiselectable="false"
aria-labelledby="label"
>
<slot></slot>
</div>
<div class="hint"></div>
Expand Down
9 changes: 8 additions & 1 deletion src/components/select/bl-select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,10 @@ export default class BlSelect<ValueType extends FormValue = string> extends Form
tabindex="${this.disabled ? '-1' : 0}"
?autofocus=${this.autofocus}
@click=${this.togglePopover}
role="button"
aria-haspopup="listbox"
aria-expanded="${this.opened}"
aria-labelledby="label"
>
<legend><span>${this.label}</span></legend>
<span class="placeholder">${this.placeholder}</span>
Expand All @@ -332,7 +336,7 @@ export default class BlSelect<ValueType extends FormValue = string> extends Form

const helpMessage = this.helpText ? html`<p class="help-text">${this.helpText}</p>` : '';

const label = this.label ? html`<label>${this.label}</label>` : '';
const label = this.label ? html`<label id="label">${this.label}</label>` : '';

return html`<div
class=${classMap({
Expand All @@ -349,6 +353,9 @@ export default class BlSelect<ValueType extends FormValue = string> extends Form
class="popover"
tabindex="${ifDefined(this._isPopoverOpen ? undefined : '-1')}"
@bl-select-option=${this._handleSelectOptionEvent}
role="listbox"
aria-multiselectable="${this.multiple}"
aria-labelledby="label"
>
<slot></slot>
</div>
Expand Down
24 changes: 24 additions & 0 deletions src/components/select/option/bl-select-option.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,30 @@ describe('bl-select', () => {
assert.instanceOf(el, BlSelectOption);
});

it('renders with default values', async () => {
const el = await fixture<BlSelectOption>(html`<bl-select-option></bl-select-option>`);

expect(el).shadowDom.equal(
`<div class="option-container">
<div class="focus-target single-option" role="option" aria-selected="false">
<slot>
</slot>
</div>
</div>
`
);
});

it('should have aria-selected attribute set to true if the option is selected', async function () {
const el = await fixture<BlSelectOption>(
html`<bl-select-option value="basketball" selected>Basketball</bl-select-option>`
);

const option = el.shadowRoot?.querySelector<HTMLButtonElement>('.focus-target');

expect(option).has.attribute('aria-selected', 'true');
});

describe('keyboard navigation', () => {
it('should get focus', async () => {
//when
Expand Down
4 changes: 4 additions & 0 deletions src/components/select/option/bl-select-option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ export default class BlSelectOption<ValueType extends FormValue = string> extend
@blur=${this.blur}
@keydown=${this.handleKeydown}
@click="${this._onClickOption}"
role="option"
aria-selected="${this.selected}"
>
<slot></slot>
</div>`;
Expand All @@ -96,6 +98,8 @@ export default class BlSelectOption<ValueType extends FormValue = string> extend
.checked="${this.selected}"
.disabled="${this.disabled}"
@bl-checkbox-change="${this._onCheckboxChange}"
role="option"
aria-selected="${this.selected}"
>
<slot></slot>
</bl-checkbox>`;
Expand Down