A bounded numeric setting
A canonical number stays separate from its locale-aware presentation.
Keyboard
- Arrow keys step within the limits.
- Home and End reach the bounds.
States covered
- Number
- Empty input
- Limits
Install this complete example and its component dependencies.
npx shadcn@latest add https://ui.bld8.dev/r/example-basic-number-field.jsonComplete source
/*!
MIT License
Copyright (c) 2026 Jaison
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
'use client';
import {useState} from 'react';
import {NumberField} from '@bld8/ui';
import '@bld8/ui/styles.css';
export default function NumberExample(){const [seats,setSeats]=useState<number|null>(4);return <div><NumberField label="Example seat count" name="seats" value={seats} onValueChange={setSeats} min={1} max={12} step={1} locale="en-AU" hint="Choose one to twelve seats."/><p>Canonical value: {seats===null?'empty':seats}</p></div>;}