Searching Open Sourcery

Type to search Open Sourcery.

Inputs & Controls

Quantity Input

A stepper input with min and max clamping, custom icons, and change events.

v1.1.0@magic-spells/quantity-input

$ npm i @magic-spells/quantity-input

GitHubnpm

Live demo

Quantity: 1

Step between 1 and 10, or type a value; it clamps at both ends.

About

A professional, highly-customizable Web Component for creating intuitive quantity input controls in e-commerce applications. Features increment/decrement buttons with an input field, perfect for shopping carts, product quantities, and any numeric input scenarios.

Features

  • Full markup control - You provide the HTML structure and icons
  • Optional default styles - Import ready-made CSS or write your own
  • Configurable constraints - Set min/max values and default quantities
  • Event-driven architecture - Clean separation between UI and logic
  • Zero dependencies - Pure Web Components
  • Lightweight and performant - Minimal footprint, maximum performance

Usage

<!-- Basic usage (defaults to min=1, value=min) -->
<quantity-input>
  <button data-action-decrement type="button">−</button>
  <input type="number" />
  <button data-action-increment type="button">+</button>
</quantity-input>

<!-- With custom min/max/value -->
<quantity-input min="1" max="10" value="5">
  <button data-action-decrement type="button">−</button>
  <input type="number" />
  <button data-action-increment type="button">+</button>
</quantity-input>

<!-- With custom icons -->
<quantity-input min="0" max="100" value="50">
  <button data-action-decrement type="button">
    <svg><!-- your minus icon --></svg>
  </button>
  <input type="number" />
  <button data-action-increment type="button">
    <svg><!-- your plus icon --></svg>
  </button>
</quantity-input>

<!-- Stepping by 5, clamped at 50 -->
<quantity-input min="0" max="50" value="10" step="5">
  <button data-action-decrement type="button">−</button>
  <input type="number" />
  <button data-action-increment type="button">+</button>

Attributes

AttributeDescriptionDefaultRequired
minMinimum allowed quantity (0 is allowed)1No
maxMaximum allowed quantitynoneNo
valueInitial/current quantity valueminNo
stepAmount each button press adds or subtracts1No
disabledDisables both buttons and the input; blocks all changesabsentNo

About, features, usage and options are taken from the package README.