brumate/ui

NumberField

A field for a number, in the format of the locale, with buttons that step it.

2 guests, a budget of 120.

<script>
  import { $bind, $signal } from 'brumate/signals';
  import Button from '@brumate/ui/Button.brm';
  import Group from '@brumate/ui/Group.brm';
  import Input from '@brumate/ui/Input.brm';
  import Label from '@brumate/ui/Label.brm';
  import NumberField from '@brumate/ui/NumberField.brm';

  let guests = $signal(2);
  let budget = $signal(120);
</script>

<div class="ui-stack">
  <NumberField class="ui-field" minValue=(1) maxValue=(12) value=$bind(guests)>
    <Label>Guests</Label>
    <Group class="ui-number">
      <Button slot="decrement" class="ui-step">−</Button>
      <Input class="ui-input" />
      <Button slot="increment" class="ui-step">+</Button>
    </Group>
  </NumberField>
  <NumberField class="ui-field" minValue=(0) step=(10) value=$bind(budget) formatOptions=({ style: 'currency', currency: 'USD' })>
    <Label>Budget</Label>
    <Group class="ui-number">
      <Button slot="decrement" class="ui-step">−</Button>
      <Input class="ui-input" />
      <Button slot="increment" class="ui-step">+</Button>
    </Group>
  </NumberField>
</div>
<p>{guests} guests, a budget of {budget}.</p>
<NumberField minValue=(0) step=(5) value=$bind(width)>
  <Label>Width</Label>
  <Group>
    <Button slot="decrement">−</Button>
    <Input />
    <Button slot="increment">+</Button>
  </Group>
</NumberField>

Format

Stepping

Names

The Buttons are named "Increase" and "Decrease" with the Label, or with the aria-label of the field, such as "Increase Quantity". aria-label and aria-labelledby on the field name its input. The Buttons are out of the order of Tab, and control the input. The input has the role of a text box with the description "Number field", as in React Aria, since a spin button cannot take focus with VoiceOver.