mirror of
https://github.com/nextui-org/nextui.git
synced 2025-12-08 19:26:11 +00:00
fix(input): input display with hidden type (#3174)
* fix(input): input display with hidden type * chore(input): add isHiddenType to dependency * refactor(input): move the styles to theme and change hidden to data attr * feat(theme): add isHiddenType to input * chore(changeset): include theme package * chore(input): revise input test * fix(theme): remove isHiddenType from variants and use data-hidden prop instead * fix(theme): remove isHiddenType from defaultVariants * fix(input): remove isHiddenType passing to input
This commit is contained in:
parent
bea1bde667
commit
dbb4b8ee56
6
.changeset/selfish-tips-joke.md
Normal file
6
.changeset/selfish-tips-joke.md
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
"@nextui-org/input": patch
|
||||
"@nextui-org/theme": patch
|
||||
---
|
||||
|
||||
Fix input display with hidden type (#3170)
|
||||
@ -153,6 +153,33 @@ describe("Input", () => {
|
||||
|
||||
expect(onClear).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("should not display input with hidden type", async () => {
|
||||
const wrapper = render(
|
||||
<>
|
||||
<Input data-testid="input-1" type="hidden" />
|
||||
<Input data-testid="input-2" />
|
||||
</>,
|
||||
);
|
||||
|
||||
const {container} = wrapper;
|
||||
|
||||
const inputBaseWrappers = container.querySelectorAll("[data-slot='base']");
|
||||
|
||||
expect(inputBaseWrappers).toHaveLength(2);
|
||||
|
||||
const inputs = container.querySelectorAll("input");
|
||||
|
||||
expect(inputs).toHaveLength(2);
|
||||
|
||||
expect(inputBaseWrappers[0]).toHaveAttribute("data-hidden");
|
||||
|
||||
expect(inputBaseWrappers[1]).not.toHaveAttribute("data-hidden");
|
||||
|
||||
expect(inputs[0]).not.toBeVisible();
|
||||
|
||||
expect(inputs[1]).toBeVisible();
|
||||
});
|
||||
});
|
||||
|
||||
describe("Input with React Hook Form", () => {
|
||||
|
||||
@ -145,9 +145,11 @@ export function useInput<T extends HTMLInputElement | HTMLTextAreaElement = HTML
|
||||
const isFilledByDefault = ["date", "time", "month", "week", "range"].includes(type!);
|
||||
const isFilled = !isEmpty(inputValue) || isFilledByDefault;
|
||||
const isFilledWithin = isFilled || isFocusWithin;
|
||||
const baseStyles = clsx(classNames?.base, className, isFilled ? "is-filled" : "");
|
||||
const isHiddenType = type === "hidden";
|
||||
const isMultiline = originalProps.isMultiline;
|
||||
|
||||
const baseStyles = clsx(classNames?.base, className, isFilled ? "is-filled" : "");
|
||||
|
||||
const handleClear = useCallback(() => {
|
||||
setInputValue("");
|
||||
|
||||
@ -286,6 +288,7 @@ export function useInput<T extends HTMLInputElement | HTMLTextAreaElement = HTML
|
||||
"data-has-helper": dataAttr(hasHelper),
|
||||
"data-has-label": dataAttr(hasLabel),
|
||||
"data-has-value": dataAttr(!isPlaceholderShown),
|
||||
"data-hidden": dataAttr(isHiddenType),
|
||||
...focusWithinProps,
|
||||
...props,
|
||||
};
|
||||
@ -307,6 +310,7 @@ export function useInput<T extends HTMLInputElement | HTMLTextAreaElement = HTML
|
||||
isFilledWithin,
|
||||
hasPlaceholder,
|
||||
focusWithinProps,
|
||||
isHiddenType,
|
||||
originalProps.isReadOnly,
|
||||
originalProps.isRequired,
|
||||
originalProps.isDisabled,
|
||||
|
||||
@ -23,7 +23,7 @@ import {dataFocusVisibleClasses, groupDataFocusVisibleClasses} from "../utils";
|
||||
*/
|
||||
const input = tv({
|
||||
slots: {
|
||||
base: "group flex flex-col",
|
||||
base: "group flex flex-col data-[hidden=true]:hidden",
|
||||
label: [
|
||||
"absolute",
|
||||
"z-10",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user