Skip to content

Commit 52fea37

Browse files
committed
fix: use text input for time
1 parent 53682fe commit 52fea37

File tree

1 file changed

+37
-34
lines changed

1 file changed

+37
-34
lines changed

src/Editor.tsx

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,16 @@ import { formatEventTime, toEventTime } from './time'
99

1010
type AddSession = {
1111
name: string
12-
hour: number
13-
minute: number
12+
hour: string
13+
minute: string
14+
}
15+
16+
const toNumber = (n: string) => {
17+
try {
18+
return parseInt(n, 10)
19+
} catch {
20+
return null
21+
}
1422
}
1523

1624
export const Editor = ({
@@ -27,16 +35,23 @@ export const Editor = ({
2735
}) => {
2836
const [add, updateAdd] = useState<AddSession>({
2937
name: '',
30-
hour: 0,
31-
minute: 0,
38+
hour: '19',
39+
minute: '45',
3240
})
3341
const inputRef = useRef<HTMLInputElement>(null)
34-
const isInputValid = () =>
35-
add.name.length > 0 &&
36-
add.hour >= 0 &&
37-
add.hour <= 23 &&
38-
add.minute >= 0 &&
39-
add.minute <= 59
42+
const isInputValid = () => {
43+
const hour = toNumber(add.hour)
44+
const minute = toNumber(add.minute)
45+
return (
46+
add.name.length > 0 &&
47+
hour !== null &&
48+
hour >= 0 &&
49+
hour <= 23 &&
50+
minute !== null &&
51+
minute >= 0 &&
52+
minute <= 59
53+
)
54+
}
4055

4156
const userTimeZone = new Intl.DateTimeFormat().resolvedOptions().timeZone
4257
const eventTime = toEventTime({ conferenceDate, userTimeZone })
@@ -75,38 +90,26 @@ export const Editor = ({
7590
<td className="time">
7691
<NumberInput
7792
ref={inputRef}
78-
type="number"
79-
min={0}
80-
max={23}
93+
type="text"
94+
inputMode="numeric"
8195
value={add.hour}
8296
onChange={({ target: { value } }) => {
83-
try {
84-
const hour = parseInt(value, 10)
85-
updateAdd({
86-
...add,
87-
hour,
88-
})
89-
} catch {
90-
// pass
91-
}
97+
updateAdd({
98+
...add,
99+
hour: value,
100+
})
92101
}}
93102
/>
94103
{':'}
95104
<NumberInput
96-
type="number"
97-
min={0}
98-
max={59}
105+
type="text"
106+
inputMode="numeric"
99107
value={add.minute}
100108
onChange={({ target: { value } }) => {
101-
try {
102-
const minute = parseInt(value, 10)
103-
updateAdd({
104-
...add,
105-
minute,
106-
})
107-
} catch {
108-
// pass
109-
}
109+
updateAdd({
110+
...add,
111+
minute: value,
112+
})
110113
}}
111114
/>
112115
</td>

0 commit comments

Comments
 (0)