Skip to content

Commit 08f425a

Browse files
committed
refactor(HourMinuteInput): Respond to PR comments
1 parent 367a8f4 commit 08f425a

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

lib/editor/components/HourMinuteInput.js

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ export default class HourMinuteInput extends Component<Props, State> {
2727
// Move to minute field when colon is typed
2828
if (key === ':') {
2929
evt.preventDefault()
30+
const focusElement = evt.currentTarget.id === 'hours' ? 'minutes' : 'seconds'
3031
// $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()
3233
return
3334
}
3435

@@ -75,6 +76,15 @@ export default class HourMinuteInput extends Component<Props, State> {
7576
const {hours, minutes, seconds} = this.state
7677

7778
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+
}
7888

7989
return (
8090
<span style={{display: 'flex', alignItems: 'baseline'}}>
@@ -94,43 +104,27 @@ export default class HourMinuteInput extends Component<Props, State> {
94104
}}
95105
value={hours && hours < 10 ? `0${hours}` : hours || defaultValue}
96106
/>
97-
<span style={{zIndex: 9, position: 'relative', left: -2.5, fontWeight: 900}}>:</span>
107+
<span style={separatorStyle}>:</span>
98108
<FormControl
99109
{...otherProps}
100110
id='minutes'
101111
onKeyDown={this._onKeyDown}
102112
onChange={this._onChange}
103113
onFocus={this._onFocus}
104114
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'}}
114116
value={minutes && minutes < 10 ? `0${minutes}` : minutes || defaultValue}
115117
/>
116118
{showSeconds && <>
117-
<span style={{zIndex: 9, position: 'relative', left: -2.5, fontWeight: 900}}>:</span>
119+
<span style={separatorStyle}>:</span>
118120
<FormControl
119121
{...otherProps}
120122
id='seconds'
121123
onKeyDown={this._onKeyDown}
122124
onChange={this._onChange}
123125
onFocus={this._onFocus}
124126
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'}}
134128
value={seconds || defaultValue}
135129
/>
136130
</>

0 commit comments

Comments
 (0)