@samitouri / QOSami-HFS / commits / 8f42559e

fix: login autofill not working correctly on firefox #341

Massimo Melina committed Sep 17, 2023 at 16:37 UTC 8f42559ef3d368bdee2576256bff3f2302dd1b8e
1 file changed +7 -7
mui-grid-form/StringField.ts
+7 -7
@@ -1,6 +1,6 @@
1 // This file is part of HFS - Copyright 2021-2023, Massimo Melina <a@rejetto.com> - License https://www.gnu.org/licenses/gpl-3.0.txt
2
3 -import { createElement as h, ReactNode, useCallback, useEffect, useRef, useState } from 'react'
3 +import { createElement as h, ReactNode, useEffect, useRef, useState } from 'react'
4 import { FieldProps } from '.'
5 import { Autocomplete, InputAdornment, TextField } from '@mui/material'
6 import { StandardTextFieldProps } from '@mui/material/TextField/TextField'
@@ -31,8 +31,7 @@ export function StringField({ value, onChange, min, max, required, setApi, typin
31 setState(normalized)
32 lastChange.current = normalized
33 }, [normalized])
34 - const valueFocusing = useRef('')
35 - const autoFillDetected = useRef(false)
34 + const valueFocusing = useRef<string | undefined>()
35 const render = (params: any) => h(TextField, {
36 fullWidth: true,
37 InputLabelProps: state || props.placeholder ? { shrink: true } : undefined,
@@ -43,16 +42,17 @@ export function StringField({ value, onChange, min, max, required, setApi, typin
42 const val = ev.target.value
43 if (onTyping?.(val) === false) return
44 setState(val)
46 - if (typing || autoFillDetected.current)
45 + if (typing || valueFocusing.current === undefined)
46 go(ev, val)
47 },
48 onKeyDown(ev) {
49 props.onKeyDown?.(ev)
51 - autoFillDetected.current = ev.code === undefined
52 - if (ev.key === 'Enter')
50 + if (ev.key === 'Enter' || ev.code === undefined) // undefined on autofill (chrome116)
51 go(ev)
52 },
55 - onFocus(ev) { valueFocusing.current = ev.target.value },
53 + onFocus(ev) {
54 + valueFocusing.current = ev.target.value
55 + },
56 onBlur(ev) {
57 props.onBlur?.(ev)
58 if (valueFocusing.current !== ev.target.value)