Skip to content

Commit 79a98d5

Browse files
authored
feat: add tabIndex option to button.ms-choice (#467)
1 parent 3dd956e commit 79a98d5

File tree

6 files changed

+72
-0
lines changed

6 files changed

+72
-0
lines changed

packages/demo/src/app-routing.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ import Options40 from './options/options40.js';
7373
import Options41 from './options/options41.js';
7474
import Options42 from './options/options42.js';
7575
import Options43 from './options/options43.js';
76+
import Options44 from './options/options44.js';
7677

7778
export const navbarRouting = [
7879
{ name: 'getting-started', view: '/src/getting-started.html', viewModel: GettingStarted, title: 'Getting Started' },
@@ -147,6 +148,7 @@ export const exampleRouting = [
147148
{ name: 'options41', view: '/src/options/options41.html', viewModel: Options41, title: 'Pre-Sort Data' },
148149
{ name: 'options42', view: '/src/options/options42.html', viewModel: Options42, title: 'Lazy Load Data' },
149150
{ name: 'options43', view: '/src/options/options43.html', viewModel: Options43, title: 'Close on Tab' },
151+
{ name: 'options44', view: '/src/options/options44.html', viewModel: Options44, title: 'tabIndex' },
150152
],
151153
},
152154
{
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<div class="row mb-2">
2+
<div class="col-md-12 title-desc">
3+
<h2 class="bd-title">
4+
tabindex <small>(for accessibility)</small>
5+
<span class="float-end links">
6+
Code <span class="fa fa-link"></span>
7+
<span class="small">
8+
<a target="_blank" href="https://github.com/ghiscoding/multiple-select-vanilla/blob/main/packages/demo/src/options/options39.html"
9+
>html</a
10+
>
11+
|
12+
<a target="_blank" href="https://github.com/ghiscoding/multiple-select-vanilla/blob/main/packages/demo/src/options/options39.ts"
13+
>ts</a
14+
>
15+
</span>
16+
</span>
17+
</h2>
18+
<div class="demo-subtitle">
19+
For accessibility reason we could add a <code>tabIndex</code>option to the button with the <code>.ms-choice</code>select button.
20+
</div>
21+
</div>
22+
</div>
23+
24+
<div>
25+
<div class="mb-10">
26+
<label class="mb-2" for="custom-label">tabIndex = 0</label>
27+
</div>
28+
<div class="mb-10">
29+
<select class="col-sm-8">
30+
<option value="1">First</option>
31+
<option value="2">Second</option>
32+
<option value="3">Third</option>
33+
<option value="4">Fourth</option>
34+
</select>
35+
</div>
36+
</div>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { type MultipleSelectInstance, multipleSelect } from 'multiple-select-vanilla';
2+
3+
export default class Example {
4+
ms1?: MultipleSelectInstance;
5+
6+
mount() {
7+
this.ms1 = multipleSelect('select', {
8+
tabIndex: 0,
9+
}) as MultipleSelectInstance;
10+
}
11+
12+
unmount() {
13+
// destroy ms instance(s) to avoid DOM leaks
14+
this.ms1?.destroy();
15+
this.ms1 = undefined;
16+
}
17+
}

packages/multiple-select-vanilla/src/MultipleSelectInstance.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ export class MultipleSelectInstance {
214214
this.choiceElm.setAttribute('aria-labelledby', this.options.labelId);
215215
}
216216

217+
if (this.options.tabIndex !== undefined) {
218+
this.choiceElm.tabIndex = this.options.tabIndex;
219+
}
220+
217221
this.choiceElm.appendChild(createDomElement('span', { className: 'ms-placeholder', textContent: this.options.placeholder }));
218222

219223
if (this.options.showClear) {

packages/multiple-select-vanilla/src/models/multipleSelectOption.interface.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,9 @@ export interface MultipleSelectOption extends MultipleSelectLocale {
247247
/** Display the OK button at bottom of the list when using multiple selection to easily close the drop, defaults to false. */
248248
showOkButton?: boolean;
249249

250+
/** add a tabIndex to the "ms-choice" button, no default */
251+
tabIndex?: number;
252+
250253
/** Defaults to False, when set to True it will use the <option label=""> (from select option value) that can be used to display selected options. */
251254
useSelectOptionLabel?: boolean;
252255

playwright/e2e/options44.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { expect, test } from '@playwright/test';
2+
3+
test.describe('Options 44 - tabIndex', () => {
4+
test('adding a tabindex to the select button', async ({ page }) => {
5+
await page.goto('#/options44');
6+
7+
const msChoice = await page.locator('.ms-choice');
8+
await expect(msChoice).toHaveAttribute('tabindex', '0');
9+
});
10+
});

0 commit comments

Comments
 (0)