Input
A styled text input built on Base UI.
registry/new-york-v4/ui/input.tsx
"use client";
import type * as React from "react";
import { cn } from "@/lib/utils";
export type InputProps = Omit<
React.ComponentProps<"input"> & React.RefAttributes<HTMLInputElement>,
"size"
> & {
size?: "sm" | "default" | "lg" | number;
unstyled?: boolean;
nativeInput?: boolean;
};
export function Input({
className,
size = "default",
unstyled = false,
nativeInput: _nativeInput = false,
style,
...props
}: InputProps): React.ReactElement {
const inputPaddingClass = unstyled ? "px-3" : "px-[calc(--spacing(3)-1px)]";
const smallInputPaddingClass = unstyled
? "px-2.5"
: "px-[calc(--spacing(2.5)-1px)]";
const inputClassName = cn(
"h-8.5 w-full min-w-0 rounded-[inherit] leading-8.5 outline-none [transition:background-color_5000000s_ease-in-out_0s] placeholder:text-muted-foreground/72 sm:h-7.5 sm:leading-7.5",
inputPaddingClass,
size === "sm" &&
cn("h-7.5 leading-7.5 sm:h-6.5 sm:leading-6.5", smallInputPaddingClass),
size === "lg" && "h-9.5 leading-9.5 sm:h-8.5 sm:leading-8.5",
props.type === "search" &&
"[&::-webkit-search-cancel-button]:appearance-none [&::-webkit-search-decoration]:appearance-none [&::-webkit-search-results-button]:appearance-none [&::-webkit-search-results-decoration]:appearance-none",
props.type === "file" &&
"text-muted-foreground file:me-3 file:bg-transparent file:text-sm file:font-medium file:text-foreground",
);
return (
<span
className={
cn(
!unstyled &&
"border-input bg-background text-foreground ring-ring/24 has-autofill:bg-foreground/4 has-focus-visible:border-ring has-aria-invalid:border-destructive/36 has-focus-visible:has-aria-invalid:border-destructive/64 has-focus-visible:has-aria-invalid:ring-destructive/16 dark:bg-input/32 dark:has-autofill:bg-foreground/8 dark:has-aria-invalid:ring-destructive/24 relative inline-flex w-full rounded-lg border text-base shadow-xs/5 transition-shadow not-dark:bg-clip-padding before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-lg)-1px)] not-has-disabled:not-has-focus-visible:not-has-aria-invalid:before:shadow-[0_1px_--theme(--color-black/4%)] has-focus-visible:ring-[3px] has-disabled:opacity-64 has-[:disabled,:focus-visible,[aria-invalid]]:shadow-none sm:text-sm dark:not-has-disabled:not-has-focus-visible:not-has-aria-invalid:before:shadow-[0_-1px_--theme(--color-white/6%)]",
className,
) || undefined
}
data-size={size}
data-slot="input-control"
>
<input
className={inputClassName}
data-slot="input"
size={typeof size === "number" ? size : undefined}
style={typeof style === "function" ? undefined : style}
{...props}
/>
</span>
);
}
No selection tags yet — empty means no evidence, not lack of support.
DependenciesBundle weight · light
- ui-primitives
- @base-ui/react@^1.4.1