Skip to content

Commit e497916

Browse files
committed
(fix/enhancement) timepicker accessibility: implemented number fields for hours/minutes, updated event listeners
1 parent 58e62d6 commit e497916

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/timepicker.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,10 @@ export class Timepicker extends Component<TimepickerOptions> {
253253
this.el.addEventListener('keydown', this._handleInputKeydown);
254254
this.plate.addEventListener('mousedown', this._handleClockClickStart);
255255
this.plate.addEventListener('touchstart', this._handleClockClickStart);
256-
this.digitalClock.addEventListener('keyup', this._inputFromTextField);
257-
this.inputHours.addEventListener('click', () => this.showView('hours'));
258-
this.inputMinutes.addEventListener('click', () => this.showView('minutes'));
256+
this.digitalClock.addEventListener('change', this._inputFromTextField);
257+
this.inputHours.addEventListener('focus', () => this.showView('hours'));
258+
this.inputMinutes.addEventListener('focus', () => this.showView('minutes'));
259+
this.inputMinutes.addEventListener('focusout', () => this.formatMinutes());
259260
}
260261

261262
_removeEventHandlers() {
@@ -567,7 +568,7 @@ export class Timepicker extends Component<TimepickerOptions> {
567568
this.hours = +value[0] || 0;
568569
this.minutes = +value[1] || 0;
569570
this.inputHours.value = this.hours;
570-
this.inputMinutes.value = Timepicker._addLeadingZero(this.minutes);
571+
this.inputMinutes.value = this.minutes;
571572

572573
this._updateAmPmView();
573574
}
@@ -639,9 +640,7 @@ export class Timepicker extends Component<TimepickerOptions> {
639640
const value = parseInt(this.inputHours.value);
640641
if (value > 0 && value < 13) {
641642
this.drawClockFromTimeInput(value, isHours);
642-
this.showView('minutes', this.options.duration / 2);
643643
this.hours = value;
644-
this.inputMinutes.focus();
645644
}
646645
else {
647646
const hour = new Date().getHours();
@@ -651,10 +650,9 @@ export class Timepicker extends Component<TimepickerOptions> {
651650
else {
652651
const value = parseInt(this.inputMinutes.value);
653652
if (value >= 0 && value < 60) {
654-
this.inputMinutes.value = Timepicker._addLeadingZero(value);
653+
this.inputMinutes.value = String(value);
655654
this.drawClockFromTimeInput(value, isHours);
656655
this.minutes = value;
657-
(<HTMLElement>this.modalEl.querySelector('.confirmation-btns :nth-child(2)')).focus();
658656
}
659657
else {
660658
const minutes = new Date().getMinutes();
@@ -759,6 +757,10 @@ export class Timepicker extends Component<TimepickerOptions> {
759757
this.bg.setAttribute('cy', cy2.toString());
760758
}
761759

760+
formatMinutes() {
761+
this.inputMinutes.value = Timepicker._addLeadingZero(Number(this.inputMinutes.value));
762+
}
763+
762764
/**
763765
* Open timepicker.
764766
*/
@@ -809,9 +811,9 @@ export class Timepicker extends Component<TimepickerOptions> {
809811
<div class="timepicker-digital-display">
810812
<div class="timepicker-text-container">
811813
<div class="timepicker-display-column">
812-
<input type="text" maxlength="2" autofocus class="timepicker-input-hours text-primary" />
814+
<input type="number" maxlength="2" autofocus class="timepicker-input-hours text-primary" min="1" max="12"/>
813815
:
814-
<input type="text" maxlength="2" class="timepicker-input-minutes" />
816+
<input type="number" maxlength="2" class="timepicker-input-minutes" min="0" max="59"/>
815817
</div>
816818
<div class="timepicker-display-column timepicker-display-am-pm">
817819
<div class="timepicker-span-am-pm"></div>

0 commit comments

Comments
 (0)