Quantity Picker
Several labelled counters behind one summary ("2 adults, 1 child"), with limits per counter and in total.
c2-quantity-picker is the guests picker of Airbnb and Booking.com: a trigger that sums up several counts and opens a panel of labelled counters, each a c2-quantity with its own limits.
Import
import '@c2n/components/quantity-picker'Usage
The summary
The trigger reads each counter’s count with its noun, singular or plural as Intl.PluralRules picks, joined in the reader’s language with Intl.ListFormat, and leaves out the counters at 0 (“2 adults, 1 child”). placeholder shows while every counter is 0, and summary replaces the whole text with a function of your own:
picker.summary = (counters) => `${counters.reduce((sum, counter) => sum + counter.value, 0)} guests`Limits and values
Each c2-quantity has min, max and step; max-total on the picker caps the sum, and at the limit every + is off and the note says so. values reads { adults: 2, children: 1, … } by each counter’s name (or its label in lower case), and total the sum. input fires on every step and change when the panel closes after a change (on every step when inline), both with { values, total }. The picker is not form-associated: send values with your form.
Keyboard and screen readers
The trigger’s name includes the label (“Guests: 2 adults, 1 child”). The panel opens on the first counter, whose value is a spinbutton: ↑ and ↓ step it, Home and End jump to its limits. Escape, a click outside or Done closes the panel and returns focus to the trigger, and each change is announced with the new summary.