Duostrap Number Field
A Duostrap numeric input with steppers, locale formatting, nullable values, and label scrubbing.
Duostrap Number Field projects classic forms.less input geometry and buttons.less beveled gradient steppers over the Base Number Field protocol, with keyboard stepping, locale formatting, nullable values, label scrubbing, and Field / Form integration.
Preview
Section titled “Preview” Web Components React Vue Vue 2
Loading interactive preview… The article and source are ready to read. Interactive controls will appear here when ready.
<div class="grid w-full max-w-xs gap-4">
<proto-ui-duostrap-number-field-root id="quantity-field">
<proto-ui-duostrap-number-field-label>
Quantity
</proto-ui-duostrap-number-field-label>
<proto-ui-duostrap-number-field-decrement>
<span aria-hidden="true">−</span>
<span class="sr-only">Decrease Quantity</span>
</proto-ui-duostrap-number-field-decrement>
<proto-ui-duostrap-number-field-input></proto-ui-duostrap-number-field-input>
<proto-ui-duostrap-number-field-increment>
<span aria-hidden="true">+</span>
<span class="sr-only">Increase Quantity</span>
</proto-ui-duostrap-number-field-increment>
</proto-ui-duostrap-number-field-root>
</div>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const root = document.querySelector('#quantity-field');
if (root instanceof HTMLElement) {
setElementProps(root, {
defaultValue: 12,
min: 0,
max: 100,
step: 1,
ariaLabel: 'Quantity',
});
}
</script>Installation
Section titled “Installation”Available starting in 0.3.0-rc.1 and later releases. Import the parts directly from @proto.ui/prototypes-duostrap/number-field:
import { numberFieldRoot, numberFieldLabel, numberFieldInput, numberFieldControl, numberFieldIncrement, numberFieldDecrement,} from '@proto.ui/prototypes-duostrap/number-field';<DuostrapNumberFieldRoot defaultValue={12} min={0} max={100} step={1} ariaLabel="Quantity"> <DuostrapNumberFieldLabel>Quantity</DuostrapNumberFieldLabel> <DuostrapNumberFieldDecrement> <span aria-hidden="true">−</span> <span className="sr-only">Decrease Quantity</span> </DuostrapNumberFieldDecrement> <DuostrapNumberFieldInput /> <DuostrapNumberFieldIncrement> <span aria-hidden="true">+</span> <span className="sr-only">Increase Quantity</span> </DuostrapNumberFieldIncrement></DuostrapNumberFieldRoot>- Editing and stepping: Incomplete text drafts remain editable until blur or
Entercommits valid numbers or restores the last accepted value. Stepper buttons restore classic Duostrap hover and active inset-shadow feedback;ArrowUp/ArrowDownstep bystep(Shiftmultiplies by 10), andHome/Endjump tomin/max. IME composition pauses parsing and stepping. - Locale formatting: Pass
localeandformatOptionsfor decimal, currency, or percent display and parsing without rounding away underlying precision. - Empty values and forms: Enable
allowEmptyso clearing commitsnull; useControlin place ofInputinsideFieldorFormFieldto connectFieldLabel, numeric validation, serialization, and reset.
Examples
Section titled “Examples”Currency and Percent Formatting
Section titled “Currency and Percent Formatting” Web Components React Vue Vue 2
Loading interactive preview… The article and source are ready to read. Interactive controls will appear here when ready.
<div class="grid w-full max-w-xs gap-4">
<proto-ui-duostrap-number-field-root id="budget-field">
<proto-ui-duostrap-number-field-label>
Budget (USD)
</proto-ui-duostrap-number-field-label>
<proto-ui-duostrap-number-field-decrement>
<span aria-hidden="true">−</span>
<span class="sr-only">Decrease Budget</span>
</proto-ui-duostrap-number-field-decrement>
<proto-ui-duostrap-number-field-input></proto-ui-duostrap-number-field-input>
<proto-ui-duostrap-number-field-increment>
<span aria-hidden="true">+</span>
<span class="sr-only">Increase Budget</span>
</proto-ui-duostrap-number-field-increment>
</proto-ui-duostrap-number-field-root>
<proto-ui-duostrap-number-field-root id="discount-field">
<proto-ui-duostrap-number-field-label>
Discount rate
</proto-ui-duostrap-number-field-label>
<proto-ui-duostrap-number-field-decrement>
<span aria-hidden="true">−</span>
<span class="sr-only">Decrease Discount rate</span>
</proto-ui-duostrap-number-field-decrement>
<proto-ui-duostrap-number-field-input></proto-ui-duostrap-number-field-input>
<proto-ui-duostrap-number-field-increment>
<span aria-hidden="true">+</span>
<span class="sr-only">Increase Discount rate</span>
</proto-ui-duostrap-number-field-increment>
</proto-ui-duostrap-number-field-root>
</div>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const budget = document.querySelector('#budget-field');
const discount = document.querySelector('#discount-field');
if (budget instanceof HTMLElement) {
setElementProps(budget, {
defaultValue: 1250,
min: 0,
max: 100000,
step: 25,
locale: 'en-US',
formatOptions: { style: 'currency', currency: 'USD' },
ariaLabel: 'Budget (USD)',
});
}
if (discount instanceof HTMLElement) {
setElementProps(discount, {
defaultValue: 0.25,
min: 0,
max: 1,
step: 0.05,
locale: 'en-US',
formatOptions: { style: 'percent' },
ariaLabel: 'Discount rate',
});
}
</script>Label Scrubbing and Nullable Values
Section titled “Label Scrubbing and Nullable Values” Web Components React Vue Vue 2
Loading interactive preview… The article and source are ready to read. Interactive controls will appear here when ready.
<div class="grid w-full max-w-xs gap-4">
<proto-ui-duostrap-number-field-root id="opacity-field">
<proto-ui-duostrap-number-field-label>
Opacity (drag label)
</proto-ui-duostrap-number-field-label>
<proto-ui-duostrap-number-field-decrement>
<span aria-hidden="true">−</span>
<span class="sr-only">Decrease Opacity</span>
</proto-ui-duostrap-number-field-decrement>
<proto-ui-duostrap-number-field-input></proto-ui-duostrap-number-field-input>
<proto-ui-duostrap-number-field-increment>
<span aria-hidden="true">+</span>
<span class="sr-only">Increase Opacity</span>
</proto-ui-duostrap-number-field-increment>
</proto-ui-duostrap-number-field-root>
<proto-ui-duostrap-number-field-root id="seats-field">
<proto-ui-duostrap-number-field-label>
Optional seat limit
</proto-ui-duostrap-number-field-label>
<proto-ui-duostrap-number-field-decrement>
<span aria-hidden="true">−</span>
<span class="sr-only">Decrease Optional seat limit</span>
</proto-ui-duostrap-number-field-decrement>
<proto-ui-duostrap-number-field-input></proto-ui-duostrap-number-field-input>
<proto-ui-duostrap-number-field-increment>
<span aria-hidden="true">+</span>
<span class="sr-only">Increase Optional seat limit</span>
</proto-ui-duostrap-number-field-increment>
</proto-ui-duostrap-number-field-root>
</div>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const opacity = document.querySelector('#opacity-field');
const seats = document.querySelector('#seats-field');
if (opacity instanceof HTMLElement) {
setElementProps(opacity, {
defaultValue: 60,
min: 0,
max: 100,
step: 1,
scrub: true,
scrubSteps: 50,
ariaLabel: 'Opacity',
});
}
if (seats instanceof HTMLElement) {
setElementProps(seats, {
defaultValue: null,
min: 1,
max: 500,
step: 1,
allowEmpty: true,
ariaLabel: 'Optional seat limit',
});
}
</script>Disabled, Read-only, and Unbounded
Section titled “Disabled, Read-only, and Unbounded” Web Components React Vue Vue 2
Loading interactive preview… The article and source are ready to read. Interactive controls will appear here when ready.
<div class="grid w-full max-w-xs gap-4">
<proto-ui-duostrap-number-field-root id="disabled-field">
<proto-ui-duostrap-number-field-label>
Disabled
</proto-ui-duostrap-number-field-label>
<proto-ui-duostrap-number-field-decrement>
<span aria-hidden="true">−</span>
<span class="sr-only">Decrease Disabled</span>
</proto-ui-duostrap-number-field-decrement>
<proto-ui-duostrap-number-field-input></proto-ui-duostrap-number-field-input>
<proto-ui-duostrap-number-field-increment>
<span aria-hidden="true">+</span>
<span class="sr-only">Increase Disabled</span>
</proto-ui-duostrap-number-field-increment>
</proto-ui-duostrap-number-field-root>
<proto-ui-duostrap-number-field-root id="readonly-field">
<proto-ui-duostrap-number-field-label>
Read-only
</proto-ui-duostrap-number-field-label>
<proto-ui-duostrap-number-field-decrement>
<span aria-hidden="true">−</span>
<span class="sr-only">Decrease Read-only</span>
</proto-ui-duostrap-number-field-decrement>
<proto-ui-duostrap-number-field-input></proto-ui-duostrap-number-field-input>
<proto-ui-duostrap-number-field-increment>
<span aria-hidden="true">+</span>
<span class="sr-only">Increase Read-only</span>
</proto-ui-duostrap-number-field-increment>
</proto-ui-duostrap-number-field-root>
<proto-ui-duostrap-number-field-root id="unbounded-field">
<proto-ui-duostrap-number-field-label>
Unbounded offset
</proto-ui-duostrap-number-field-label>
<proto-ui-duostrap-number-field-decrement>
<span aria-hidden="true">−</span>
<span class="sr-only">Decrease Unbounded offset</span>
</proto-ui-duostrap-number-field-decrement>
<proto-ui-duostrap-number-field-input></proto-ui-duostrap-number-field-input>
<proto-ui-duostrap-number-field-increment>
<span aria-hidden="true">+</span>
<span class="sr-only">Increase Unbounded offset</span>
</proto-ui-duostrap-number-field-increment>
</proto-ui-duostrap-number-field-root>
</div>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const disabled = document.querySelector('#disabled-field');
const readOnly = document.querySelector('#readonly-field');
const unbounded = document.querySelector('#unbounded-field');
if (disabled instanceof HTMLElement)
setElementProps(disabled, { defaultValue: 42, disabled: true });
if (readOnly instanceof HTMLElement)
setElementProps(readOnly, { defaultValue: 24, readOnly: true });
if (unbounded instanceof HTMLElement) {
setElementProps(unbounded, {
defaultValue: 3.14,
min: null,
max: null,
step: 0.5,
snapToStep: false,
});
}
</script>Controlled
Section titled “Controlled” Web Components React Vue Vue 2
Loading interactive preview… The article and source are ready to read. Interactive controls will appear here when ready.
<div class="grid w-full max-w-xs gap-4">
<proto-ui-duostrap-number-field-root id="controlled-field">
<proto-ui-duostrap-number-field-label>
Controlled volume
</proto-ui-duostrap-number-field-label>
<proto-ui-duostrap-number-field-decrement>
<span aria-hidden="true">−</span>
<span class="sr-only">Decrease Controlled volume</span>
</proto-ui-duostrap-number-field-decrement>
<proto-ui-duostrap-number-field-input></proto-ui-duostrap-number-field-input>
<proto-ui-duostrap-number-field-increment>
<span aria-hidden="true">+</span>
<span class="sr-only">Increase Controlled volume</span>
</proto-ui-duostrap-number-field-increment>
</proto-ui-duostrap-number-field-root>
<div
id="controlled-status"
role="status"
aria-live="polite"
class="text-xs text-muted-foreground tabular-nums"
>
Accepted value: 25 · Commits: 0
</div>
</div>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const root = document.querySelector('#controlled-field');
const status = document.querySelector('#controlled-status');
let value = 25;
let commits = 0;
const sync = () => {
if (root instanceof HTMLElement) {
setElementProps(root, {
value,
min: 0,
max: 100,
step: 5,
allowEmpty: true,
});
}
if (status)
status.textContent =
'Accepted value: ' +
(value ?? 'empty') +
' · Commits: ' +
commits;
};
sync();
root?.addEventListener('valueChange', (event) => {
value = event.detail.value;
sync();
});
root?.addEventListener('valueCommit', (event) => {
value = event.detail.value;
commits += 1;
sync();
});
</script>RTL Layout and Scrubbing
Section titled “RTL Layout and Scrubbing” Web Components React Vue Vue 2
Loading interactive preview… The article and source are ready to read. Interactive controls will appear here when ready.
<div dir="rtl" class="grid w-full max-w-xs gap-4">
<proto-ui-duostrap-number-field-root id="rtl-field">
<proto-ui-duostrap-number-field-label>
الكمية (اسحب التسمية)
</proto-ui-duostrap-number-field-label>
<proto-ui-duostrap-number-field-decrement>
<span aria-hidden="true">−</span>
<span class="sr-only">إنقاص الكمية</span>
</proto-ui-duostrap-number-field-decrement>
<proto-ui-duostrap-number-field-input></proto-ui-duostrap-number-field-input>
<proto-ui-duostrap-number-field-increment>
<span aria-hidden="true">+</span>
<span class="sr-only">زيادة الكمية</span>
</proto-ui-duostrap-number-field-increment>
</proto-ui-duostrap-number-field-root>
</div>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const root = document.querySelector('#rtl-field');
if (root instanceof HTMLElement) {
setElementProps(root, {
defaultValue: 40,
min: 0,
max: 100,
step: 5,
direction: 'rtl',
scrub: true,
scrubSteps: 20,
ariaLabel: 'الكمية',
});
}
</script>Root Props
Section titled “Root Props”| Prop | Type | Default |
|---|---|---|
value | number null | — |
defaultValue | number null | 0 |
min | number null | 0 |
max | number null | 100 |
step | number | 1 |
snapToStep | boolean | true |
disabled | boolean | false |
readOnly | boolean | false |
required | boolean | false |
ariaLabel | string | '' |
name | string | '' |
allowEmpty | boolean | false |
locale | string | — |
formatOptions | NumberFieldFormatOptions | — |
scrub | boolean | false |
scrubSteps | number | 100 |
direction | 'ltr' 'rtl' | 'ltr' |
Events, Methods, and States
Section titled “Events, Methods, and States”| Member | Signature / Type | Part |
|---|---|---|
valueChange | Event<{ value: number null }> | Root |
valueCommit | Event<{ value: number null }> | Root |
getValue() | () => number null | Root / Input / Control |
requestValue(next) | (value: number null) => boolean | Root |
commitValue() | () => void | Root |
stepBy(direction) | (direction: number) => boolean | Root |
resetValue() | () => boolean | Root / Input / Control |
empty / dragging / formatInvalid / draft | ExposeState | Root |
disabled / focusVisible | ExposeState<boolean> | Increment / Decrement |