Skip to content

Commit 2c0f065

Browse files
committed
(fix/enhancement) timepicker accessibility: implemented tabindex states on modal open/close
1 parent aec7b95 commit 2c0f065

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/timepicker.ts

+18-4
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,23 @@ export class Timepicker extends Component<TimepickerOptions> {
361361

362362
_setupModal() {
363363
this.modal = Modal.init(this.modalEl, {
364-
onOpenStart: this.options.onOpenStart,
364+
onOpenStart: () => {
365+
if (typeof this.options.onOpenStart === 'function') {
366+
this.options.onOpenStart.call(this);
367+
}
368+
this.modalEl.querySelectorAll('.btn').forEach((e: HTMLButtonElement) => {
369+
if (e.style.visibility !== 'hidden') e.setAttribute('tabindex', '0');
370+
});
371+
},
365372
onOpenEnd: this.options.onOpenEnd,
366-
onCloseStart: this.options.onCloseStart,
373+
onCloseStart: () => {
374+
if (typeof this.options.onCloseStart === 'function') {
375+
this.options.onCloseStart.call(this);
376+
}
377+
this.modalEl.querySelectorAll('.btn').forEach((e: HTMLButtonElement) => {
378+
e.setAttribute('tabindex', '-1');
379+
});
380+
},
367381
onCloseEnd: () => {
368382
if (typeof this.options.onCloseEnd === 'function') {
369383
this.options.onCloseEnd.call(this);
@@ -394,10 +408,10 @@ export class Timepicker extends Component<TimepickerOptions> {
394408

395409
private _createButton(text: string, visibility: string): HTMLButtonElement {
396410
const button = document.createElement('button');
397-
button.classList.add('btn-flat', 'waves-effect');
411+
button.classList.add('btn', 'btn-flat', 'waves-effect', 'text');
398412
button.style.visibility = visibility;
399413
button.type = 'button';
400-
button.tabIndex = this.options.twelveHour ? 3 : 1;
414+
button.tabIndex = -1;
401415
button.innerText = text;
402416
return button;
403417
}

0 commit comments

Comments
 (0)