Skip to content

Commit 219a133

Browse files
committed
(fix/enhancement) timepicker hours/minutes HTML5 number input support for enhancing keyboard accessibility
1 parent e497916 commit 219a133

File tree

2 files changed

+28
-16
lines changed

2 files changed

+28
-16
lines changed

sass/components/_timepicker.scss

+11-7
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@
3434
user-select: none;
3535
padding: 1rem 1rem 1.5rem 1rem;
3636

37-
input[type=text]{
37+
input[type=number] {
3838
height: 4rem;
3939
color: var(--md-sys-color-secondary);
40-
border-bottom: 0px;
40+
border-bottom: 0;
4141
font-size: 4rem;
4242
direction: ltr;
4343
}
@@ -49,18 +49,18 @@
4949
cursor: pointer;
5050
}
5151

52-
input[type=text].timepicker-input-hours {
52+
input[type=number].timepicker-input-hours {
5353
text-align: right;
5454
width: 28%;
5555
margin-right: 3px;
5656
}
5757

58-
input[type=text].timepicker-input-minutes {
58+
input[type=number].timepicker-input-minutes {
5959
width: 33%;
6060
margin-left: 3px;
6161
}
6262

63-
input[type=text].text-primary {
63+
input[type=number].text-primary {
6464
color: var(--md-sys-color-on-background);
6565
}
6666

@@ -217,8 +217,12 @@ input[type=text].text-primary {
217217
margin-top: 1.2rem;
218218
}
219219

220-
input[type=text].timepicker-input-minutes {
221-
min-width: 5.3rem;
220+
input[type=number].timepicker-input-hours {
221+
min-width: 6rem;
222+
}
223+
224+
input[type=number].timepicker-input-minutes {
225+
min-width: 6.5rem;
222226
}
223227

224228
.timepicker-modal .am-btn,

src/timepicker.ts

+17-9
Original file line numberDiff line numberDiff line change
@@ -639,25 +639,33 @@ export class Timepicker extends Component<TimepickerOptions> {
639639
if (isHours) {
640640
const value = parseInt(this.inputHours.value);
641641
if (value > 0 && value < 13) {
642-
this.drawClockFromTimeInput(value, isHours);
643642
this.hours = value;
644643
}
644+
else if(value == 0) {
645+
this.hours = 12;
646+
this.inputHours.value = this.hours.toString();
647+
}
645648
else {
646-
const hour = new Date().getHours();
647-
this.inputHours.value = (hour % 12).toString();
649+
this.hours = 1;
650+
this.inputHours.value = this.hours.toString();
648651
}
652+
this.drawClockFromTimeInput(this.hours, isHours);
649653
}
650654
else {
651655
const value = parseInt(this.inputMinutes.value);
652656
if (value >= 0 && value < 60) {
653-
this.inputMinutes.value = String(value);
654-
this.drawClockFromTimeInput(value, isHours);
657+
this.inputMinutes.value = Timepicker._addLeadingZero(value);
655658
this.minutes = value;
656659
}
660+
else if(value == -1) {
661+
this.minutes = 59;
662+
this.inputMinutes.value = Timepicker._addLeadingZero(this.minutes.toString());
663+
}
657664
else {
658-
const minutes = new Date().getMinutes();
659-
this.inputMinutes.value = Timepicker._addLeadingZero(minutes);
665+
this.minutes = 0;
666+
this.inputMinutes.value = Timepicker._addLeadingZero(this.minutes);
660667
}
668+
this.drawClockFromTimeInput(value, isHours);
661669
}
662670
}
663671

@@ -811,9 +819,9 @@ export class Timepicker extends Component<TimepickerOptions> {
811819
<div class="timepicker-digital-display">
812820
<div class="timepicker-text-container">
813821
<div class="timepicker-display-column">
814-
<input type="number" maxlength="2" autofocus class="timepicker-input-hours text-primary" min="1" max="12"/>
822+
<input type="number" maxlength="2" autofocus class="timepicker-input-hours text-primary"/>
815823
:
816-
<input type="number" maxlength="2" class="timepicker-input-minutes" min="0" max="59"/>
824+
<input type="number" maxlength="2" class="timepicker-input-minutes"/>
817825
</div>
818826
<div class="timepicker-display-column timepicker-display-am-pm">
819827
<div class="timepicker-span-am-pm"></div>

0 commit comments

Comments
 (0)