Forms

Number field

Enters a number, with buttons and keys to step it, written the way the reader's locale writes numbers.

Installation

npx sinaui add number-field

Examples

Basic

Hold a button to keep stepping, faster the longer you hold. The buttons stop at the limits.

<script lang="ts">
	import NumberField from '#lib/ui/NumberField.svelte';

	let copies = $state(3);
</script>

<NumberField label="Copies to make" bind:value={copies} min={1} max={20} name="copies" />

With a unit

Any Intl number format: units, currency, decimals. Typed values snap to the step when you leave the field.

<script lang="ts">
	import NumberField from '#lib/ui/NumberField.svelte';

	let ink = $state(2.5);
</script>

<NumberField
	label="Ink per page"
	bind:value={ink}
	min={0.5}
	max={10}
	step={0.5}
	format={{ style: 'unit', unit: 'milliliter', maximumFractionDigits: 1 }}
/>

Percent

Type 15 and it means 15%.

Up to 50% for students of the House of Wisdom.

<script lang="ts">
	import NumberField from '#lib/ui/NumberField.svelte';

	let discount = $state(0.1);
</script>

<!-- Typing "15" means 15%; the value is 0.15. -->
<NumberField
	label="Scholar's discount"
	bind:value={discount}
	min={0}
	max={0.5}
	step={0.05}
	format={{ style: 'percent' }}
	hint="Up to 50% for students of the House of Wisdom."
/>

Props

PropTypeDefault
labelstring (required)
valuenumber, bindable
min, maxnumber
stepnumber1
formatIntl.NumberFormatOptions
localestring'en'
namestring
hint, errorstring
disabledbooleanfalse

Accessibility

  • A text field, so phones show a number keyboard and screen readers read what was typed as typed.
  • The buttons are skipped by Tab (the arrow keys do the same job) but screen readers can press them, and each change is announced.
  • Buttons are 44px on touch screens; holding one is the same as pressing it repeatedly.
KeyAction
↑ ↓Step up / down.
Page Up Page DownTen steps up / down.
Home EndMinimum / maximum.
EnterTake what was typed.
Introduction
Theming
Changelog
Button
Action button
Confirm button
Copy button
Hold to confirm
Split button
Calendar
Checkbox
Color picker
Combobox
Date picker
Date range picker
File drop
Form
Input
Mention input
Multi select
Number field
OTP input
Password input
Phone input
Radio cards
Radio group
Rich text editor
Search field
Segmented control
Select
Signature pad
Slider
Switch
Tag input
Upload
Wheel picker
Textarea
Time field
Toggle group
Toolbar
Alert dialog
Command palette
Context menu
Dialog
Drawer
Dropdown
Hover card
Popover
Tooltip
Announcement bar
Alert
Empty state
Meter
Progress
Rolling number
Skeleton
Spinner
Toast
Avatar
Avatar group
Badge
Card
Carousel
Chart
Chat
Code block
Data table
Folder
Kbd
Mind map
Resizable panels
Scroll area
Separator
Sortable
Table
Tag group
Virtual list
Audio player
Image
Image compare
Video
Visualizer
Breadcrumb
File tree
Menubar
Navigation menu
Pagination
Sidebar layout
Stepper
Tabs
Alarm clock
Clock
Dynamic island
Fluid orb
Hourglass
Stopwatch
Timer
AI chat
AI media
Auth
Board
Booking
Dashboard
File explorer
Messaging
Notifications
Settings
Team
Overview
Pricing
Agent chat
Calendar
Voice agent
Mail inbox
CMS
Blog
Marketing site
E-commerce
AI agents
SaaS landing page
SaaS app
Accordion
Dark theme
Light theme