Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions packages/components/input/__tests__/input.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,33 +224,6 @@ describe("Input", () => {

expect(onClear).toHaveBeenCalledTimes(0);
});

it("should focus input on click", async () => {
const {getByTestId} = render(<Input data-testid="input" />);

const input = getByTestId("input") as HTMLInputElement;
const innerWrapper = document.querySelector("[data-slot='inner-wrapper']") as HTMLDivElement;
const inputWrapper = document.querySelector("[data-slot='input-wrapper']") as HTMLDivElement;

const user = userEvent.setup();

expect(document.activeElement).not.toBe(input);

await user.click(input);
expect(document.activeElement).toBe(input);
input.blur();
expect(document.activeElement).not.toBe(input);

await user.click(innerWrapper);
expect(document.activeElement).toBe(input);
input.blur();
expect(document.activeElement).not.toBe(input);

await user.click(inputWrapper);
expect(document.activeElement).toBe(input);
input.blur();
expect(document.activeElement).not.toBe(input);
});
});

describe("Input with React Hook Form", () => {
Expand Down
23 changes: 11 additions & 12 deletions packages/components/input/src/use-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,6 @@ export function useInput<T extends HTMLInputElement | HTMLTextAreaElement = HTML
domRef.current?.focus();
}, [setInputValue, onClear]);

const handleInputWrapperClick = useCallback(() => {
if (domRef.current) {
domRef.current?.focus();
}
}, [domRef.current]);

// if we use `react-hook-form`, it will set the input value using the ref in register
// i.e. setting ref.current.value to something which is uncontrolled
// hence, sync the state with `ref.current.value`
Expand Down Expand Up @@ -226,11 +220,6 @@ export function useInput<T extends HTMLInputElement | HTMLTextAreaElement = HTML
onPress: handleClear,
});

const {pressProps: inputWrapperPressProps} = usePress({
isDisabled: !!originalProps?.isDisabled || !!originalProps?.isReadOnly,
onPress: handleInputWrapperClick,
});

const isInvalid = validationState === "invalid" || isAriaInvalid;

const labelPlacement = useMemo<InputVariantProps["labelPlacement"]>(() => {
Expand Down Expand Up @@ -409,7 +398,12 @@ export function useInput<T extends HTMLInputElement | HTMLTextAreaElement = HTML
className: slots.inputWrapper({
class: clsx(classNames?.inputWrapper, isFilled ? "is-filled" : ""),
}),
...mergeProps(props, hoverProps, inputWrapperPressProps),
...mergeProps(props, hoverProps),
onClick: (e) => {
if (domRef.current && e.currentTarget === e.target) {
domRef.current.focus();
}
},
style: {
cursor: "text",
...props.style,
Expand All @@ -433,6 +427,11 @@ export function useInput<T extends HTMLInputElement | HTMLTextAreaElement = HTML
...props,
ref: innerWrapperRef,
"data-slot": "inner-wrapper",
onClick: (e) => {
if (domRef.current && e.currentTarget === e.target) {
domRef.current.focus();
}
},
className: slots.innerWrapper({
class: clsx(classNames?.innerWrapper, props?.className),
}),
Expand Down