Skip to content

Commit

Permalink
chore(input): rollback PR3533 (#3720)
Browse files Browse the repository at this point in the history
  • Loading branch information
wingkwong authored Sep 6, 2024
1 parent 123b7fb commit 485b865
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 60 deletions.
5 changes: 0 additions & 5 deletions .changeset/long-ducks-do.md

This file was deleted.

20 changes: 0 additions & 20 deletions packages/components/input/__tests__/input.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,26 +126,6 @@ describe("Input", () => {
expect(ref.current?.value)?.toBe(value);
});

it("setting ref should sync the internal value", () => {
const ref = React.createRef<HTMLInputElement>();

const {container} = render(<Input ref={ref} type="text" />);

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();

Expand Down
37 changes: 2 additions & 35 deletions packages/components/input/src/use-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -131,40 +131,7 @@ export function useInput<T extends HTMLInputElement | HTMLTextAreaElement = HTML
const disableAnimation =
originalProps.disableAnimation ?? globalContext?.disableAnimation ?? false;

const domRef = useRef<T>(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<T>(ref);

const baseDomRef = useDOMRef<HTMLDivElement>(baseRef);
const inputWrapperRef = useDOMRef<HTMLDivElement>(wrapperRef);
Expand Down

0 comments on commit 485b865

Please sign in to comment.