coss.com Svelte

Number Field

A numeric input element with increment and decrement buttons, and a scrub area.

Loading p-number-field-1 preview…

Installation

pnpm dlx shadcn-svelte@latest add https://coss-sv.vercel.app/r/number-field.json

Usage

<script lang="ts">
  import * as NumberField from "$lib/components/ui/number-field/index.js";
</script>

<NumberField.Root defaultValue={0}>
  <NumberField.ScrubArea label="Quantity" />
  <NumberField.Group>
    <NumberField.Decrement />
    <NumberField.Input />
    <NumberField.Increment />
  </NumberField.Group>
</NumberField.Root>

API Reference

NumberField.Root

Root component for the local Svelte number-field behavior.

PropTypeDefaultDescription
size"sm" \| "default" \| "lg""default"Controls the size of all child components through context

NumberField.Group

Container for the input and buttons.

NumberField.Input

Input element for the numeric value.

NumberField.Increment

Button that increments the value and displays the Hugeicons add glyph.

NumberField.Decrement

Button that decrements the value and displays the Hugeicons minus glyph.

NumberField.ScrubArea

Draggable area for scrubbing the value.

PropTypeDefaultDescription
labelstring-Label text displayed in the scrub area

Examples

For accessible labelling and validation, prefer using Field to wrap number fields. See Number field.

Small Size

Loading p-number-field-2 preview…

Large Size

Loading p-number-field-3 preview…

Disabled

Loading p-number-field-4 preview…

With External Label

Loading p-number-field-5 preview…

With Scrub

Loading p-number-field-6 preview…

With Range

Loading p-number-field-7 preview…

With Formatted Value

Loading p-number-field-8 preview…

With Step

Loading p-number-field-9 preview…

Form Integration

Loading p-number-field-10 preview…