From 485b8653de1f86dadb4e9451c35a3e56e2eee5e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D5=A1=D3=84=D5=A1?= Date: Fri, 6 Sep 2024 10:13:18 +0800 Subject: [PATCH] chore(input): rollback PR3533 (#3720) --- .changeset/long-ducks-do.md | 5 --- .../components/input/__tests__/input.test.tsx | 20 ---------- packages/components/input/src/use-input.ts | 37 +------------------ 3 files changed, 2 insertions(+), 60 deletions(-) delete mode 100644 .changeset/long-ducks-do.md diff --git a/.changeset/long-ducks-do.md b/.changeset/long-ducks-do.md deleted file mode 100644 index b956db24e..000000000 --- a/.changeset/long-ducks-do.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@nextui-org/input": patch ---- - -syncs changes to ref value to internal (state) value (#3024, #3436) diff --git a/packages/components/input/__tests__/input.test.tsx b/packages/components/input/__tests__/input.test.tsx index 64af9c2e3..23859a06d 100644 --- a/packages/components/input/__tests__/input.test.tsx +++ b/packages/components/input/__tests__/input.test.tsx @@ -126,26 +126,6 @@ describe("Input", () => { expect(ref.current?.value)?.toBe(value); }); - it("setting ref should sync the internal value", () => { - const ref = React.createRef(); - - const {container} = render(); - - if (!ref.current) { - throw new Error("ref is null"); - } - - ref.current!.value = "value"; - - const input = container.querySelector("input")!; - - input.focus(); - - const internalValue = input.value; - - expect(ref.current?.value)?.toBe(internalValue); - }); - it("should clear the value and onClear is triggered", async () => { const onClear = jest.fn(); diff --git a/packages/components/input/src/use-input.ts b/packages/components/input/src/use-input.ts index e97e350f3..8e43f26b0 100644 --- a/packages/components/input/src/use-input.ts +++ b/packages/components/input/src/use-input.ts @@ -15,7 +15,7 @@ import {useDOMRef, filterDOMProps} from "@nextui-org/react-utils"; import {useFocusWithin, useHover, usePress} from "@react-aria/interactions"; import {clsx, dataAttr, isEmpty, objectToDeps, safeAriaLabel, warn} from "@nextui-org/shared-utils"; import {useControlledState} from "@react-stately/utils"; -import {useMemo, Ref, useCallback, useState, useImperativeHandle, useRef} from "react"; +import {useMemo, Ref, useCallback, useState} from "react"; import {chain, mergeProps} from "@react-aria/utils"; import {useTextField} from "@react-aria/textfield"; @@ -131,40 +131,7 @@ export function useInput(null); - - let proxy: T | undefined = undefined; - - useImperativeHandle( - ref, - () => { - if (proxy === undefined) { - proxy = new Proxy(domRef.current!, { - get(target, prop) { - const value = target[prop]; - - if (value instanceof Function) { - return value.bind(target); - } - - return value; - }, - set(target, prop, value) { - target[prop] = value; - - if (prop === "value") { - setInputValue(value); - } - - return true; - }, - }); - } - - return proxy; - }, - [domRef.current], - ); + const domRef = useDOMRef(ref); const baseDomRef = useDOMRef(baseRef); const inputWrapperRef = useDOMRef(wrapperRef);