-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add new
labelId
option for accessibility (#254)
- Loading branch information
1 parent
5443ff9
commit f66852f
Showing
7 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<div class="row mb-2"> | ||
<div class="col-md-12 title-desc"> | ||
<h2 class="bd-title"> | ||
Label Id <small>(for accessibility)</small> | ||
<span class="float-end links"> | ||
Code <span class="fa fa-link"></span> | ||
<span class="small"> | ||
<a | ||
target="_blank" | ||
href="https://github.com/ghiscoding/multiple-select-vanilla/blob/main/packages/demo/src/options/options03.html" | ||
>html</a | ||
> | ||
| | ||
<a target="_blank" href="https://github.com/ghiscoding/multiple-select-vanilla/blob/main/packages/demo/src/options/options03.ts" | ||
>ts</a | ||
> | ||
</span> | ||
</span> | ||
</h2> | ||
<div class="demo-subtitle"> | ||
In order for the select to be accessible, it should be linked to a label, use <code>labelId</code> option | ||
to associate your label to the select button (the label must be created by yourself and linked via the <code>for</code> attribute). | ||
Using this option will link the <code>id</code> and <code>aria-labelledby</code> of the <code>.ms-choice</code> select button with your custom label. | ||
</div> | ||
<div class="demo-subtitle"> | ||
Clicking the label will open the select dropdown. | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div> | ||
<div class="mb-10"> | ||
<label class="mb-2" for="custom-label">My Select Label</label> | ||
</div> | ||
<div class="mb-10"> | ||
<select class="col-sm-8"> | ||
<option value="1">First</option> | ||
<option value="2">Second</option> | ||
<option value="3">Third</option> | ||
<option value="4">Fourth</option> | ||
</select> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { type MultipleSelectInstance, multipleSelect } from 'multiple-select-vanilla'; | ||
|
||
export default class Example { | ||
ms1?: MultipleSelectInstance; | ||
|
||
mount() { | ||
this.ms1 = multipleSelect('select', { | ||
labelId: 'custom-label', | ||
}) as MultipleSelectInstance; | ||
} | ||
|
||
unmount() { | ||
// destroy ms instance(s) to avoid DOM leaks | ||
this.ms1?.destroy(); | ||
this.ms1 = undefined; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { test, expect } from '@playwright/test'; | ||
|
||
test.describe('Options 39 - Label ID', () => { | ||
test('adding a Label id to the select button', async ({ page }) => { | ||
await page.goto('#/options39'); | ||
|
||
const msChoice = await page.locator('.ms-choice'); | ||
await expect(msChoice).toHaveAttribute('id', 'custom-label'); | ||
await expect(msChoice).toHaveAttribute('aria-labelledby', 'custom-label'); | ||
}); | ||
}); |