Skip to content

Commit e6f3628

Browse files
Prakash7895Prakash Choudhary
andauthored
fix(components): number input label #2268 fixed (#2274)
* fix(components): number input label #2268 fixed * fix(component): comments resolved * fix(component): format with prettier --------- Co-authored-by: Prakash Choudhary <prakashchoudhary@Prakashs-iMac.local>
1 parent f75174d commit e6f3628

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

.changeset/polite-ravens-hide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@nextui-org/input": patch
3+
---
4+
5+
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.

packages/components/input/src/use-input.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {useFocusRing} from "@react-aria/focus";
66
import {input} from "@nextui-org/theme";
77
import {useDOMRef, filterDOMProps} from "@nextui-org/react-utils";
88
import {useFocusWithin, useHover, usePress} from "@react-aria/interactions";
9-
import {clsx, dataAttr, safeAriaLabel} from "@nextui-org/shared-utils";
9+
import {clsx, dataAttr, isEmpty, safeAriaLabel} from "@nextui-org/shared-utils";
1010
import {useControlledState} from "@react-stately/utils";
1111
import {useMemo, Ref, useCallback, useState} from "react";
1212
import {chain, mergeProps} from "@react-aria/utils";
@@ -124,7 +124,7 @@ export function useInput<T extends HTMLInputElement | HTMLTextAreaElement = HTML
124124
const Component = as || "div";
125125

126126
const isFilledByDefault = ["date", "time", "month", "week", "range"].includes(type!);
127-
const isFilled = !!inputValue || isFilledByDefault;
127+
const isFilled = !isEmpty(inputValue) || isFilledByDefault;
128128
const isFilledWithin = isFilled || isFocusWithin;
129129
const baseStyles = clsx(classNames?.base, className, isFilled ? "is-filled" : "");
130130
const isMultiline = originalProps.isMultiline;
@@ -289,7 +289,9 @@ export function useInput<T extends HTMLInputElement | HTMLTextAreaElement = HTML
289289
"data-filled-within": dataAttr(isFilledWithin),
290290
"data-has-start-content": dataAttr(hasStartContent),
291291
"data-has-end-content": dataAttr(!!endContent),
292-
className: slots.input({class: clsx(classNames?.input, !!inputValue ? "is-filled" : "")}),
292+
className: slots.input({
293+
class: clsx(classNames?.input, isFilled ? "is-filled" : ""),
294+
}),
293295
...mergeProps(
294296
focusProps,
295297
inputProps,
@@ -332,7 +334,7 @@ export function useInput<T extends HTMLInputElement | HTMLTextAreaElement = HTML
332334
"data-focus-visible": dataAttr(isFocusVisible),
333335
"data-focus": dataAttr(isFocused),
334336
className: slots.inputWrapper({
335-
class: clsx(classNames?.inputWrapper, !!inputValue ? "is-filled" : ""),
337+
class: clsx(classNames?.inputWrapper, isFilled ? "is-filled" : ""),
336338
}),
337339
...mergeProps(props, hoverProps),
338340
onClick: (e) => {

0 commit comments

Comments
 (0)