Number Field
A numeric field with increment, decrement, constraints and locale formatting.
Give your AI assistant this page as context.
Connect your library with MCPui/number-fieldUsage
Get this component from a saved library export or the connected CLI. The imports below refer to local files installed in your app.
Import styles/components.css, then styles/theme.css once. Wrap your app in ThemeScope from components/ui/utils so typography, focus and overlays share the theme. The installation guide covers runtime dependencies and React/Next.js setup.
import { NumberField } from './components/ui/number-field';
<NumberField label="Team size" defaultValue={5} min={1} max={100}/>Design system
This component consumes your semantic colors, spacing, typography and shape tokens. Import the compiled styles and your theme once as described in Export.
Behavior and accessibility
- Provide meaningful labels for interactive controls.
- Connect action callbacks to your application logic.
- Verify keyboard navigation and contrast in your application.
Status: experimental during early access. Sample previews do not send emails, process payments or upload files to a service.
Source and props
This is the exported source, using the same implementation as the editor.
"use client";
import { useId, type ComponentProps } from "react";
import { NumberField as Base } from "@base-ui/react/number-field";
import { cx } from "./utils";
export type NumberFieldProps = Omit<
ComponentProps<typeof Base.Root>,
"className" | "children"
> & {
label: string;
className?: string;
};
export function NumberField({
label,
id,
className,
step = 1,
defaultValue = 0,
locale = "en-US",
...props
}: NumberFieldProps) {
const generatedId = useId();
const inputId = id ?? generatedId;
return (
<Base.Root
{...props}
id={inputId}
step={step}
defaultValue={defaultValue}
locale={locale}
className={cx("cr-number-field", className)}
>
<Base.ScrubArea>
<label htmlFor={inputId} className="cr-label">
{label}
</label>
<Base.ScrubAreaCursor>
<svg
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
aria-hidden="true"
>
<path d="m5 8-4 4 4 4M1 12h22m-4-4 4 4-4 4" />
</svg>
</Base.ScrubAreaCursor>
</Base.ScrubArea>
<Base.Group className="cr-number-group">
<Base.Decrement aria-label={"Decrease " + label}>
<svg
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
aria-hidden="true"
>
<path d="M5 12h14" />
</svg>
</Base.Decrement>
<Base.Input />
<Base.Increment aria-label={"Increase " + label}>
<svg
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
aria-hidden="true"
>
<path d="M5 12h14M12 5v14" />
</svg>
</Base.Increment>
</Base.Group>
</Base.Root>
);
}