Quantity Picker
Several labelled counters behind one summary ("2 adults, 1 child"), with limits per counter and in total.
c2-quantity-picker
The guests picker of Airbnb and Booking.com: a trigger that sums up several counts ("2 adults, 1 child") and opens a
panel of labelled counters, each a c2-quantity child with its own limits.
The summary joins each counter's count and noun (singular/plural, chosen with Intl.PluralRules) with
Intl.ListFormat, leaving out counters at 0; summary replaces it with a function of your own, and placeholder
shows while every counter is 0. max-total caps the sum: at the limit every + is off and the note says so.
inline drops the trigger and the popover, for a booking panel that shows the counters directly.
The panel is a popover under the trigger: Escape, a click outside or "Done" closes it and focus returns to the
trigger. Each counter's value is a spinbutton (↑ ↓ Home End), and a change is announced with the new summary.
input fires on every step and change when the panel closes after a change (at once when inline), both with
{ values, total }. The picker is form-associated: inside a <form> each counter with a name submits its count
under that name; a form reset restores the counts the counters started with, and a disabled fieldset disables it.
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
label | string | — | What is counted ("Guests"): the trigger's caption and the group's name. |
placeholder | string | — | The trigger's text while every counter is 0. Default: "None". |
max-total | CustomEvent | — | The most the counters may add up to. |
inline | boolean | false | Shows the counters directly, with no trigger or popover. |
disabled | boolean | false | Turns the trigger and every counter off. |
open | boolean | false | Whether the panel is open. |
Slots
| Name | Description |
|---|---|
(default) | The c2-quantity counters. |
chevron-icon | The trigger's chevron. |
Events
| Name | Type | Description |
|---|---|---|
input | CustomEvent<{ values: Record<string, number>; total: number }> | Fired on every step. |
change | CustomEvent<{ values: Record<string, number>; total: number }> | Fired when the panel closes after a change, or on every step when inline. |
CSS parts
Shadow DOM styling hooks used with ::part(name). Prefer CSS custom properties when they cover the change.
| Name | Description |
|---|---|
trigger | The button that opens the panel. |
panel | The panel of counters. |
CSS custom properties
Grouped by semantic target and state from --c2-<component>__<target>__<state>--<property>. Click a group to collapse it; click a name to copy it.
| Name | Type | Default | Description |
|---|---|---|---|
--c2-quantity-picker--width | pixel | 280px | The trigger's width. |
--c2-quantity-picker__panel--width | pixel | 320px | |
--c2-quantity-picker__panel--padding | padding | 8px 16px | |
--c2-quantity-picker__panel--border | border | 1px solid #e4e4e7 | |
--c2-quantity-picker__panel--border-radius | border-radius | 8px | |
--c2-quantity-picker__panel--background | color | #ffffff | |
--c2-quantity-picker__panel--box-shadow | shadow | 0 8px 24px rgba(0, 0, 0, 0.12) | |
--c2-quantity-picker__trigger--padding | padding | 8px 12px | |
--c2-quantity-picker__trigger--border | border | 1px solid #bcbcc6 | |
--c2-quantity-picker__trigger--border-radius | border-radius | 6px | |
--c2-quantity-picker__trigger--background | color | #ffffff | |
--c2-quantity-picker__trigger--color | color | #18181b | |
--c2-quantity-picker__trigger__hover--border | border | 1px solid #a1a1aa | |
--c2-quantity-picker__trigger__open--border | border | 1px solid rgb(2, 101, 220) | |
--c2-quantity-picker__trigger__focus--outline | outline | 2px solid rgba(2, 101, 220, 0.4) | |
--c2-quantity-picker__label--color | color | #71717a | |
--c2-quantity-picker__label--font-size | font-size | 12px | |
--c2-quantity-picker__divider--border | border | 1px solid #e4e4e7 | The line above the panel's footer; the counters draw their own (--c2-quantity__divider--border). |
--c2-quantity-picker__note--color | color | #71717a | |
--c2-quantity-picker__note--font-size | font-size | 12px | |
Text and languages
The text the component shows, in English. It shows another language when the app adds one with addTranslations, under quantity-picker, and the nearest lang asks for it; any message not translated stays in English. {0}, {1}… stand for the values a message carries. Languages guide.
| Key | English | Values |
|---|---|---|
none | None | — |
done | Done | — |
decrease | Decrease {0} | {0} label |
increase | Increase {0} | {0} label |
upTo | Up to {0} | {0} max |
full | {0} of {1}, the most allowed | {0} total {1} max |
changed | Now {0} | {0} summary |
c2-quantity
One counter of a c2-quantity-picker: a label, an optional hint and a stepper. The reader steps it with the − and
- buttons, or with ↑ ↓ Home End on its value, which is a spinbutton (the one tab stop of the counter).
singular and plural are the nouns the picker's summary uses ("2 adults, 1 child"); a counter
without them is summed into the summary as its label. name is its key in the picker's values.
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
value | number | 0 | The count. |
min | number | 0 | The least it may count. |
max | CustomEvent | — | The most this counter allows; the picker's max-total may stop it sooner. |
step | number | 1 | How much each press or arrow key adds or takes away. |
name | string | — | The counter's key in the picker's values. Default: its label in lower case. |
singular | string | — | The singular noun of the summary ("adult"). |
plural | string | — | The plural noun of the summary ("adults"). |
disabled | boolean | false | Turns the counter's buttons and keys off. |
Slots
| Name | Description |
|---|---|
(default) | The counter's label ("Adults"). |
hint | A line under the label ("Ages 13 or above"). |
decrement-icon | The − button's icon. |
increment-icon | The + button's icon. |
CSS parts
Shadow DOM styling hooks used with ::part(name). Prefer CSS custom properties when they cover the change.
| Name | Description |
|---|---|
stepper | The − value + group. |
CSS custom properties
Grouped by semantic target and state from --c2-<component>__<target>__<state>--<property>. Click a group to collapse it; click a name to copy it.
| Name | Type | Default | Description |
|---|---|---|---|
--c2-quantity--padding | padding | 12px 0 | |
--c2-quantity--gap | pixel | 12px | |
--c2-quantity__label--font-weight | font-weight | 500 | |
--c2-quantity__hint--color | color | #71717a | |
--c2-quantity__hint--font-size | font-size | 12px | |
--c2-quantity__button--size | pixel | 32px | |
--c2-quantity__button--border | border | 1px solid #bcbcc6 | |
--c2-quantity__button--border-radius | border-radius | 999px | |
--c2-quantity__button--color | color | #18181b | |
--c2-quantity__button--background | color | transparent | |
--c2-quantity__button__hover--border | border | 1px solid #a1a1aa | |
--c2-quantity__button__disabled--opacity | opacity | 0.38 | |
--c2-quantity__focus--outline | outline | 2px solid rgba(2, 101, 220, 0.4) | |
--c2-quantity__value--min-width | pixel | 24px | |
--c2-quantity__divider--border | border | 1px solid #e4e4e7 | The line above every counter of a picker after the first. |