Skip to content

Commit 8cc76a6

Browse files
committed
fix(ui): losing focus after input
1 parent b9b02c5 commit 8cc76a6

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

src/app/components/EditorContacts.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
Table,
66
UncontrolledTooltip,
77
} from "design-react-kit";
8-
import { get } from "lodash";
8+
import { debounce, get } from "lodash";
99
import { useController, useFieldArray, useFormContext } from "react-hook-form";
1010
import { useTranslation } from "react-i18next";
1111

@@ -34,6 +34,9 @@ export default function EditorContacts(): JSX.Element {
3434
});
3535
const { t } = useTranslation();
3636
const buttonRef = useRef<HTMLButtonElement>(null);
37+
const debouncedOnChangeRef = useRef<
38+
Record<string, ReturnType<typeof debounce>>
39+
>({});
3740

3841
return (
3942
<div className="form-group">
@@ -88,21 +91,31 @@ export default function EditorContacts(): JSX.Element {
8891
value === ""
8992
? undefined
9093
: value,
91-
},
94+
}
9295
);
9396

97+
const fieldKey = `${index}.${subfield}`;
98+
if (!debouncedOnChangeRef.current[fieldKey]) {
99+
debouncedOnChangeRef.current[fieldKey] = debounce(
100+
reg.onChange,
101+
500
102+
);
103+
}
104+
94105
return (
95106
<td key={subfield}>
96107
<Input
97108
{...reg}
109+
onChange={debouncedOnChangeRef.current[fieldKey]}
110+
label={true}
98111
innerRef={ref}
99112
valid={
100113
get(errors, `${fieldName}.${index}.${subfield}`) &&
101114
false
102115
}
103116
validationText={get(
104117
errors,
105-
`${fieldName}.${index}.${subfield}.message`,
118+
`${fieldName}.${index}.${subfield}.message`
106119
)}
107120
/>
108121
</td>

src/app/components/EditorDescriptionInput.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export default function EditorInput<
5050

5151
useEffect(() => {
5252
const tooltipTriggerList = document.querySelectorAll(
53-
'[data-bs-toggle="tooltip"]',
53+
'[data-bs-toggle="tooltip"]'
5454
);
5555
tooltipTriggerList.forEach((tooltipTriggerEl) => {
5656
new Tooltip(tooltipTriggerEl);
@@ -83,6 +83,7 @@ export default function EditorInput<
8383
name={name}
8484
value={(value as string) || ""}
8585
innerRef={ref}
86+
label={true}
8687
// label={`${label}${extraLangInfo}${required ? " *" : ""}${
8788
// deprecated ? ` - ${t(`editor.form.deprecatedField`)}` : ""
8889
// }`}
@@ -91,7 +92,7 @@ export default function EditorInput<
9192
valid={get(errors, `description.${lang}.${fieldName}`) && false}
9293
validationText={get(
9394
errors,
94-
`description.${lang}.${fieldName}.message`,
95+
`description.${lang}.${fieldName}.message`
9596
)}
9697
rows={textarea ? 3 : undefined}
9798
/>

src/app/components/EditorInput.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export default function EditorInput<
7171
name={name}
7272
value={value || ""}
7373
innerRef={ref}
74+
label={true}
7475
// label={`${label}${required ? " *" : ""}${
7576
// deprecated ? ` - ${t(`editor.form.deprecatedField`)}` : ""
7677
// }`}

0 commit comments

Comments
 (0)