Skip to content

Commit

Permalink
feat(select): accessibility improvement on select and option component
Browse files Browse the repository at this point in the history
fix(select): role and ari-label attribute

fix(select): style issue
  • Loading branch information
mehmetcan.boz committed May 24, 2023
1 parent 227741e commit a02a69d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/components/select/bl-select.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ describe('bl-select', () => {
assert.shadowDom.equal(
el,
`
<div class="select-wrapper">
<div
class="select-wrapper"
role="list-box"
aria-multiselectable="true"
aria-labelledby="label"
>
<fieldset
class="select-input"
tabindex="0"
Expand Down
5 changes: 4 additions & 1 deletion src/components/select/bl-select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,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 @@ -343,6 +343,9 @@ export default class BlSelect<ValueType extends FormValue = string> extends Form
'dirty': this.dirty,
})}
@keydown=${this.handleKeydown}
aria-labelledby="label"
role="list-box"
aria-multiselectable="true"
>
${label} ${this.inputTemplate()}
<div
Expand Down
28 changes: 28 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,34 @@ 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
aria-selected="false"
class="option-container"
role="option"
>
<div class="focus-target single-option">
<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>('.option-container');

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

describe('keyboard navigation', () => {
it('should get focus', async () => {
//when
Expand Down
2 changes: 1 addition & 1 deletion src/components/select/option/bl-select-option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export default class BlSelectOption<ValueType extends FormValue = string> extend
}

render() {
return html`<div class="option-container">
return html`<div class="option-container" role="option" aria-selected="${this.selected}">
${this.multiple ? this.checkboxOptionTemplate() : this.singleOptionTemplate()}
</div>`;
}
Expand Down

0 comments on commit a02a69d

Please sign in to comment.