Skip to content

Commit

Permalink
refactor(HourMinuteInput): Respond to PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
philip-cline committed Oct 9, 2023
1 parent 367a8f4 commit 08f425a
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions lib/editor/components/HourMinuteInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ export default class HourMinuteInput extends Component<Props, State> {
// Move to minute field when colon is typed
if (key === ':') {
evt.preventDefault()
const focusElement = evt.currentTarget.id === 'hours' ? 'minutes' : 'seconds'
// $FlowFixMe this is a terrible hack, but unless we upgrade to react 17 and use modern refs, this is not possible otherwise
document.getElementById('minutes').select()
document.getElementById(focusElement).select()
return
}

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

const defaultValue = typeof minutes === 'undefined' && typeof hours === 'undefined' ? '' : '00'
const separatorStyle = {zIndex: 9, position: 'relative', left: -2.5, fontWeight: 900}
const minuteSecondInputStyle = {
borderBottomRightRadius: standaloneInput ? 3 : 0,
borderLeft: 'none',
borderRadius: 0,
borderTopRightRadius: standaloneInput ? 3 : 0,
marginLeft: -5,
...style
}

return (
<span style={{display: 'flex', alignItems: 'baseline'}}>
Expand All @@ -94,43 +104,27 @@ export default class HourMinuteInput extends Component<Props, State> {
}}
value={hours && hours < 10 ? `0${hours}` : hours || defaultValue}
/>
<span style={{zIndex: 9, position: 'relative', left: -2.5, fontWeight: 900}}>:</span>
<span style={separatorStyle}>:</span>
<FormControl
{...otherProps}
id='minutes'
onKeyDown={this._onKeyDown}
onChange={this._onChange}
onFocus={this._onFocus}
placeholder={'mm'}
style={{
borderBottomRightRadius: standaloneInput ? 3 : 0,
borderLeft: 'none',
borderRadius: 0,
borderTopRightRadius: standaloneInput ? 3 : 0,
marginLeft: -5,
width: '6.5ch',
...style
}}
style={{...minuteSecondInputStyle, width: '6.5ch'}}
value={minutes && minutes < 10 ? `0${minutes}` : minutes || defaultValue}
/>
{showSeconds && <>
<span style={{zIndex: 9, position: 'relative', left: -2.5, fontWeight: 900}}>:</span>
<span style={separatorStyle}>:</span>
<FormControl
{...otherProps}
id='seconds'
onKeyDown={this._onKeyDown}
onChange={this._onChange}
onFocus={this._onFocus}
placeholder={'ss'}
style={{
borderBottomRightRadius: standaloneInput ? 3 : 0,
borderLeft: 'none',
borderRadius: 0,
borderTopRightRadius: standaloneInput ? 3 : 0,
marginLeft: -5,
width: '5.5ch',
...style
}}
style={{...minuteSecondInputStyle, width: '5.5ch'}}
value={seconds || defaultValue}
/>
</>
Expand Down

0 comments on commit 08f425a

Please sign in to comment.