Skip to content

Commit 23fa351

Browse files
authored
fix: time editor erases value as you type (supabase#43348)
## Problem When using chrome, it's impossible to enter a time value ## Solution Avoid controlling the input value and only bubble up the change when the value is a valid time or is empty ## How to test - Create a table with a `time` column - Add a new row and start entering a value using the keyboard
1 parent 57c5c7b commit 23fa351

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

apps/studio/components/grid/components/editor/TimeEditor.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import * as React from 'react'
2-
import type { RenderEditCellProps } from 'react-data-grid'
31
import dayjs from 'dayjs'
42
import customParseFormat from 'dayjs/plugin/customParseFormat'
3+
import * as React from 'react'
4+
import type { RenderEditCellProps } from 'react-data-grid'
55

66
dayjs.extend(customParseFormat)
77

@@ -29,23 +29,26 @@ function BaseEditor<TRow, TSummaryRow = unknown>({
2929
onClose,
3030
}: TimeEditorProps<TRow, TSummaryRow>) {
3131
const value = row[column.key as keyof TRow] as unknown as string
32-
const timeValue = value ? dayjs(value, format).format(INPUT_TIME_FORMAT) : value
3332

3433
function onChange(event: React.ChangeEvent<HTMLInputElement>) {
3534
const _value = event.target.value
35+
3636
if (_value == '') {
3737
onRowChange({ ...row, [column.key]: null })
3838
} else {
39-
const _timeValue = dayjs(_value, INPUT_TIME_FORMAT).format(format)
40-
onRowChange({ ...row, [column.key]: _timeValue })
39+
const dayJsValue = dayjs(_value, format)
40+
if (dayJsValue.isValid()) {
41+
const _timeValue = dayJsValue.format(format)
42+
onRowChange({ ...row, [column.key]: _timeValue })
43+
}
4144
}
4245
}
4346

4447
return (
4548
<input
4649
className="sb-grid-time-editor"
4750
ref={autoFocusAndSelect}
48-
value={timeValue ?? ''}
51+
defaultValue={value ?? ''}
4952
onChange={onChange}
5053
onBlur={() => onClose(true)}
5154
type="time"

0 commit comments

Comments
 (0)