diff --git a/.changeset/rich-berries-switch.md b/.changeset/rich-berries-switch.md new file mode 100644 index 0000000000..6b1fc15a91 --- /dev/null +++ b/.changeset/rich-berries-switch.md @@ -0,0 +1,6 @@ +--- +"@nextui-org/input": patch +"@nextui-org/theme": patch +--- + +revised styles and logic for input with file type (#2397, #2311, #2965) diff --git a/packages/components/input/src/use-input.ts b/packages/components/input/src/use-input.ts index b5ced5c3cf..0cc2102725 100644 --- a/packages/components/input/src/use-input.ts +++ b/packages/components/input/src/use-input.ts @@ -13,7 +13,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, isEmpty, objectToDeps, safeAriaLabel} from "@nextui-org/shared-utils"; +import {clsx, dataAttr, isEmpty, objectToDeps, safeAriaLabel, warn} 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"; @@ -147,6 +147,7 @@ export function useInput(() => { + if (isFileTypeInput) { + // if `labelPlacement` is not defined, choose `outside` instead + // since the default value `inside` is not supported in file input + if (!originalProps.labelPlacement) return "outside"; + + // throw a warning if `labelPlacement` is `inside` + // and change it to `outside` + if (originalProps.labelPlacement === "inside") { + warn("Input with file type doesn't support inside label. Converting to outside ..."); + + return "outside"; + } + } if ((!originalProps.labelPlacement || originalProps.labelPlacement === "inside") && !label) { return "outside"; } @@ -271,10 +293,14 @@ export function useInput ( + + ); diff --git a/packages/core/theme/src/components/input.ts b/packages/core/theme/src/components/input.ts index 6383904052..ea925ff4af 100644 --- a/packages/core/theme/src/components/input.ts +++ b/packages/core/theme/src/components/input.ts @@ -43,6 +43,7 @@ const input = tv({ "w-full font-normal bg-transparent !outline-none placeholder:text-foreground-500 focus-visible:outline-none", "data-[has-start-content=true]:ps-1.5", "data-[has-end-content=true]:pe-1.5", + "file:cursor-pointer file:bg-transparent file:border-0", ], clearButton: [ "p-2", @@ -594,13 +595,7 @@ const input = tv({ label: ["group-data-[filled-within=true]:pointer-events-auto"], }, }, - // labelPlacement=[outside,outside-left] - { - labelPlacement: ["outside", "outside-left"], - class: { - input: "h-full", - }, - }, + // labelPlacement=[outside] & isMultiline { labelPlacement: "outside", isMultiline: false,