From 5e72510befeb40a4b5adb6e9cd1ce6aa2ae194e4 Mon Sep 17 00:00:00 2001 From: Tilen Komel Date: Fri, 6 Sep 2024 09:33:13 +0200 Subject: [PATCH] Removed submit button --- .../PageComponents/Config/Security.tsx | 3 +-- src/components/UI/Generator.tsx | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/components/PageComponents/Config/Security.tsx b/src/components/PageComponents/Config/Security.tsx index c0555015..550b55e0 100644 --- a/src/components/PageComponents/Config/Security.tsx +++ b/src/components/PageComponents/Config/Security.tsx @@ -120,8 +120,7 @@ export const Security = (): JSX.Element => { <> onSubmit={onSubmit} - submitType="onSubmit" - hasSubmitButton={true} + submitType="onChange" defaultValues={{ ...config.security, ...{ diff --git a/src/components/UI/Generator.tsx b/src/components/UI/Generator.tsx index ed228a5c..7d589be4 100644 --- a/src/components/UI/Generator.tsx +++ b/src/components/UI/Generator.tsx @@ -50,6 +50,21 @@ const Generator = React.forwardRef( }, ref, ) => { + const inputRef = React.useRef(null); + + // Invokes onChange event on the input element when the value changes from the parent component + React.useEffect(() => { + if (!inputRef.current) return; + const setValue = Object.getOwnPropertyDescriptor( + HTMLInputElement.prototype, + "value", + )?.set; + + if (!setValue) return; + inputRef.current.value = ""; + setValue.call(inputRef.current, value); + inputRef.current.dispatchEvent(new Event("input", { bubbles: true })); + }, [value]); return ( <> ( onChange={inputChange} action={action} disabled={disabled} + ref={inputRef} />