@@ -27,8 +27,9 @@ export default class HourMinuteInput extends Component<Props, State> {
27
27
// Move to minute field when colon is typed
28
28
if ( key === ':' ) {
29
29
evt . preventDefault ( )
30
+ const focusElement = evt . currentTarget . id === 'hours' ? 'minutes' : 'seconds'
30
31
// $FlowFixMe this is a terrible hack, but unless we upgrade to react 17 and use modern refs, this is not possible otherwise
31
- document . getElementById ( 'minutes' ) . select ( )
32
+ document . getElementById ( focusElement ) . select ( )
32
33
return
33
34
}
34
35
@@ -75,6 +76,15 @@ export default class HourMinuteInput extends Component<Props, State> {
75
76
const { hours , minutes, seconds} = this . state
76
77
77
78
const defaultValue = typeof minutes === 'undefined' && typeof hours === 'undefined' ? '' : '00'
79
+ const separatorStyle = { zIndex : 9 , position : 'relative' , left : - 2.5 , fontWeight : 900 }
80
+ const minuteSecondInputStyle = {
81
+ borderBottomRightRadius : standaloneInput ? 3 : 0 ,
82
+ borderLeft : 'none' ,
83
+ borderRadius : 0 ,
84
+ borderTopRightRadius : standaloneInput ? 3 : 0 ,
85
+ marginLeft : - 5 ,
86
+ ...style
87
+ }
78
88
79
89
return (
80
90
< span style = { { display : 'flex' , alignItems : 'baseline' } } >
@@ -94,43 +104,27 @@ export default class HourMinuteInput extends Component<Props, State> {
94
104
} }
95
105
value = { hours && hours < 10 ? `0${ hours } ` : hours || defaultValue }
96
106
/>
97
- < span style = { { zIndex : 9 , position : 'relative' , left : - 2.5 , fontWeight : 900 } } > :</ span >
107
+ < span style = { separatorStyle } > :</ span >
98
108
< FormControl
99
109
{ ...otherProps }
100
110
id = 'minutes'
101
111
onKeyDown = { this . _onKeyDown }
102
112
onChange = { this . _onChange }
103
113
onFocus = { this . _onFocus }
104
114
placeholder = { 'mm' }
105
- style = { {
106
- borderBottomRightRadius : standaloneInput ? 3 : 0 ,
107
- borderLeft : 'none' ,
108
- borderRadius : 0 ,
109
- borderTopRightRadius : standaloneInput ? 3 : 0 ,
110
- marginLeft : - 5 ,
111
- width : '6.5ch' ,
112
- ...style
113
- } }
115
+ style = { { ...minuteSecondInputStyle , width : '6.5ch' } }
114
116
value = { minutes && minutes < 10 ? `0${ minutes } ` : minutes || defaultValue }
115
117
/>
116
118
{ showSeconds && < >
117
- < span style = { { zIndex : 9 , position : 'relative' , left : - 2.5 , fontWeight : 900 } } > :</ span >
119
+ < span style = { separatorStyle } > :</ span >
118
120
< FormControl
119
121
{ ...otherProps }
120
122
id = 'seconds'
121
123
onKeyDown = { this . _onKeyDown }
122
124
onChange = { this . _onChange }
123
125
onFocus = { this . _onFocus }
124
126
placeholder = { 'ss' }
125
- style = { {
126
- borderBottomRightRadius : standaloneInput ? 3 : 0 ,
127
- borderLeft : 'none' ,
128
- borderRadius : 0 ,
129
- borderTopRightRadius : standaloneInput ? 3 : 0 ,
130
- marginLeft : - 5 ,
131
- width : '5.5ch' ,
132
- ...style
133
- } }
127
+ style = { { ...minuteSecondInputStyle , width : '5.5ch' } }
134
128
value = { seconds || defaultValue }
135
129
/>
136
130
</ >
0 commit comments