fix(input): prevent clearable when input is readonly (#3643)

* fix(input): prevent clearable when input is readonly

* test(input): add tests for isReadOnly and isClearable interaction

* chore(changeset): add changeset for fixing clear button visibility with isReadOnly

* fix(input): disable clear button from input is readonly

* test(input): disable clear button when input is readonly

* chore(changeset): update changeset

* chore(changeset): revise message

---------

Co-authored-by: WK Wong <wingkwong.code@gmail.com>
This commit is contained in:
ryoon 2024-09-03 20:48:06 +09:00 committed by GitHub
parent f36df4362f
commit 3d6865586f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 33 additions and 1 deletions

View File

@ -0,0 +1,5 @@
---
"@nextui-org/input": patch
---
disable clear button when input is read-only

View File

@ -200,6 +200,33 @@ describe("Input", () => {
expect(inputs[1]).toBeVisible();
});
it("should disable clear button when isReadOnly is true", async () => {
const onClear = jest.fn();
const ref = React.createRef<HTMLInputElement>();
const {getByRole} = render(
<Input
ref={ref}
isClearable
isReadOnly
defaultValue="readOnly test for clear button"
label="test input"
onClear={onClear}
/>,
);
const clearButton = getByRole("button");
expect(clearButton).not.toBeNull();
const user = userEvent.setup();
await user.click(clearButton);
expect(onClear).toHaveBeenCalledTimes(0);
});
});
describe("Input with React Hook Form", () => {

View File

@ -248,7 +248,7 @@ export function useInput<T extends HTMLInputElement | HTMLTextAreaElement = HTML
});
const {pressProps: clearPressProps} = usePress({
isDisabled: !!originalProps?.isDisabled,
isDisabled: !!originalProps?.isDisabled || !!originalProps?.isReadOnly,
onPress: handleClear,
});