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
5 changes: 5 additions & 0 deletions .changeset/polite-ravens-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nextui-org/input": patch
---

Fix #2268, when using a number input and with a 0 for the initial value, the label (default or labelPlacement='inside') does not animate to the correct position. Even when the user is setting the value to 0, the label does not alter its state unless a number other than 0 is inputted.
10 changes: 6 additions & 4 deletions packages/components/input/src/use-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {useFocusRing} from "@react-aria/focus";
import {input} from "@nextui-org/theme";
import {useDOMRef, filterDOMProps} from "@nextui-org/react-utils";
import {useFocusWithin, useHover, usePress} from "@react-aria/interactions";
import {clsx, dataAttr, safeAriaLabel} from "@nextui-org/shared-utils";
import {clsx, dataAttr, isEmpty, safeAriaLabel} from "@nextui-org/shared-utils";
import {useControlledState} from "@react-stately/utils";
import {useMemo, Ref, useCallback, useState} from "react";
import {chain, mergeProps} from "@react-aria/utils";
Expand Down Expand Up @@ -124,7 +124,7 @@ export function useInput<T extends HTMLInputElement | HTMLTextAreaElement = HTML
const Component = as || "div";

const isFilledByDefault = ["date", "time", "month", "week", "range"].includes(type!);
const isFilled = !!inputValue || isFilledByDefault;
const isFilled = !isEmpty(inputValue) || isFilledByDefault;
const isFilledWithin = isFilled || isFocusWithin;
const baseStyles = clsx(classNames?.base, className, isFilled ? "is-filled" : "");
const isMultiline = originalProps.isMultiline;
Expand Down Expand Up @@ -289,7 +289,9 @@ export function useInput<T extends HTMLInputElement | HTMLTextAreaElement = HTML
"data-filled-within": dataAttr(isFilledWithin),
"data-has-start-content": dataAttr(hasStartContent),
"data-has-end-content": dataAttr(!!endContent),
className: slots.input({class: clsx(classNames?.input, !!inputValue ? "is-filled" : "")}),
className: slots.input({
class: clsx(classNames?.input, isFilled ? "is-filled" : ""),
}),
...mergeProps(
focusProps,
inputProps,
Expand Down Expand Up @@ -332,7 +334,7 @@ export function useInput<T extends HTMLInputElement | HTMLTextAreaElement = HTML
"data-focus-visible": dataAttr(isFocusVisible),
"data-focus": dataAttr(isFocused),
className: slots.inputWrapper({
class: clsx(classNames?.inputWrapper, !!inputValue ? "is-filled" : ""),
class: clsx(classNames?.inputWrapper, isFilled ? "is-filled" : ""),
}),
...mergeProps(props, hoverProps),
onClick: (e) => {
Expand Down