fix: admin/config: mis-focusing on last row of mime types
Massimo Melina committed
May 27, 2022 at 15:55 UTC
92cf04d7060f968691528d060d8090095b8f861b
1 file changed
+6
-4
admin/src/StringStringField.ts
+6
-4
@@ -20,8 +20,6 @@ const useStyles = makeStyles({
20
export default function StringStringField({ value, onChange, keyLabel='key', valueLabel='value', keyWidth=5, valueWidth=5, actionsWidth=1 }: FieldProps<Dict<string>> & { keyLabel:string }) {
21
const refNew = useRef()
22
const justEntered = useRef<any>()
23
- useEffect(() => justEntered.current?.focus?.(),
24
- [justEntered.current]) //eslint-disable-line
23
const styles = useStyles()
24
return h(Grid, { container: true },
25
// header
@@ -50,7 +48,11 @@ export default function StringStringField({ value, onChange, keyLabel='key', val
48
})),
49
h(Grid, { key:'v', item: true, xs: valueWidth, },
50
h(StringField, {
53
- inputRef: justEntered.current === id ? justEntered : undefined,
51
+ inputRef(el: HTMLInputElement) {
52
+ if (justEntered.current !== id) return
53
+ el?.focus()
54
+ justEntered.current = null
55
+ },
56
value: v,
57
onChange(v, { was, ...rest }){
58
if (v instanceof Error) return
@@ -81,7 +83,7 @@ export default function StringStringField({ value, onChange, keyLabel='key', val
83
more.cancel()
84
if (value && v in value)
85
return alert(keyLabel + " entry already present")
84
- justEntered.current = v
86
+ justEntered.current = v // the way dom is manipulated will cause focus on wrong element, so we have to re-focus
87
onChange({ ...value, [v]:'' }, { ...more, was:value })
88
}
89
})),