Number input

Number inputs are used to increase or decrease numeric values.

Examples

Base

Label
<div class="chi-form__item">
  <chi-label for="example__base">Label</chi-label>
  <chi-number-input id="example__base"></chi-number-input>
</div>
This HTML Blueprint requires JavaScript. You may use your own solution, or use Chi's vanilla JavaScript solution, Chi.js.
<div class="chi-form__item">
  <label class="chi-label" for="example__base">Label</label>
  <div class="chi-number-input">
    <input id="example__base" type="number" class="chi-input" value="0" aria-label="Input Label">
    <button aria-label="Decrease"></button>
    <button aria-label="Increase"></button>
  </div>
</div>

<script>chi.numberInput(document.getElementById('example__base'));</script>

Disabled

Use the disabled boolean attribute to prevent users from interacting with an input. Disabled inputs are not submitted with the form and can not receive any browsing events such as mouse clicks or focus. Note: The required attribute can not be used on inputs with a disabled attribute specified.

Label
<div class="chi-form__item">
  <chi-label for="example__disabled">Label</chi-label>
  <chi-number-input disabled id="example__disabled"></chi-number-input>
</div>
This HTML Blueprint requires JavaScript. You may use your own solution, or use Chi's vanilla JavaScript solution, Chi.js.
<div class="chi-form__item">
  <label class="chi-label" for="example__disabled">Label</label>
  <div class="chi-number-input">
    <input id="example__disabled" type="number" class="chi-input" value="0" aria-label="Input Label" disabled>
    <button aria-label="Decrease"></button>
    <button aria-label="Increase"></button>
  </div>
</div>

<script>chi.numberInput(document.getElementById('example__disabled'));</script>

Min/Max/Step

Use the min and max attributes to define minimum and maximum values on number inputs. Use the step attribute to indicate the expected granularity.

This example only accepts values between 1 and 6, and as the step is 2 and initial value is 1, only odd values are valid. Use the chiNumberInvalid event described in the events section to check if the entered value is valid.

Label
<div class="chi-form__item">
  <chi-label for="example__mms">Label</chi-label>
  <chi-number-input id="example__mms" min="1" max="6" step="2" value="1"></chi-number-input>
</div>
This HTML Blueprint requires JavaScript. You may use your own solution, or use Chi's vanilla JavaScript solution, Chi.js.
<div class="chi-form__item">
  <label class="chi-label" for="example__mms">Label</label>
  <div class="chi-number-input">
    <input id="example__mms" type="number" class="chi-input" min="0" max="6" step="2" value="1" aria-label="Input Label">
    <button aria-label="Decrease"></button>
    <button aria-label="Increase"></button>
  </div>
</div>

<script>
  chi.numberInput(
    document.getElementById('example__mms'),
    {autofix: true}
  );
</script>

Required

Use the required boolean attribute to indicate which inputs must be completed before submitting a form. To render a required input, apply the required attribute to the input. It is also encouraged but not mandatory to apply a required attribute to the corresponding label of the input which will automatically render a red asterisk. Note: For HTML Blueprint implementations, the required attribute is not supported on the label. Please use the alternate method specified below for rendering a red asterisk within the label.

Label
<div class="chi-form__item">
  <chi-label for="example__required" required>Label</chi-label>
  <chi-number-input id="example__required" required></chi-number-input>
</div>
This HTML Blueprint requires JavaScript. You may use your own solution, or use Chi's vanilla JavaScript solution, Chi.js.
<div class="chi-form__item">
  <label class="chi-label" for="example__required">
    Label
    <abbr class="chi-label__required" aria-label="Required field">*</abbr>
  </label>
  <div class="chi-number-input">
    <input id="example__required" type="number" class="chi-input" value="0" aria-label="Input Label" required>
    <button aria-label="Decrease"></button>
    <button aria-label="Increase"></button>
  </div>
</div>

<script>chi.numberInput(document.getElementById('example__required'));</script>

Help

Use chi-label's attributes infoIcon and infoIconMessage to include a help icon that displays helpful information in a popover.

Label
<div class="chi-form__item">
  <chi-label for="example__help" info-icon info-icon-message="Helpful information goes here.">Label</chi-label>
  <chi-number-input id="example__help"></chi-number-input>
</div>
This HTML Blueprint requires JavaScript. You may use your own solution, or use Chi's vanilla JavaScript solution, Chi.js.
<div class="chi-form__item">
  <div class="chi-label__wrapper">
    <label class="chi-label" for="example__help">Label</label>
    <div class="chi-label__help">
      <div class="chi-button -icon -flat -xs" id="example__help-button" data-target="#example__help-popover" aria-label="Help">
        <div class="chi-button__content">
          <i class="chi-icon icon-circle-info-outline" aria-hidden="true"></i>
        </div>
      </div>
      <section class="chi-popover chi-popover--top" id="example__help-popover" aria-modal="true" role="dialog">
        <div class="chi-popover__content">
          <p class="chi-popover__text">Helpful information goes here.</p>
        </div>
      </section>
    </div>
  </div>
  <div class="chi-number-input">
    <input id="example__help" type="number" class="chi-input" value="0" aria-label="Input Label" required>
    <button aria-label="Decrease"></button>
    <button aria-label="Increase"></button>
  </div>
</div>

<script>chi.popover(document.getElementById('example__help-button'));</script>

Message

Add a message below an input to store descriptions, validation feedback, and other helpful information.

Label
<div class="chi-form__item">
  <chi-label for="example__message">Label</chi-label>
  <chi-number-input id="example__message" helper-message="Optional helper message"></chi-number-input>
</div>
This HTML Blueprint requires JavaScript. You may use your own solution, or use Chi's vanilla JavaScript solution, Chi.js.
<div class="chi-form__item">
  <label class="chi-label" for="example__message">Label</label>
  <div class="chi-number-input">
    <input id="example__message" type="number" class="chi-input" value="0" aria-label="Input Label">
    <button aria-label="Decrease"></button>
    <button aria-label="Increase"></button>
  </div>
  <div class="chi-label -status">Optional helper message</div>
</div>

<script>chi.numberInput(document.getElementById('example__message'));</script>

Error

Use danger to provide feedback to users when input data fails to validate. To meet accessibility requirements, danger inputs must include an error message explaining the failure and/or how to correct it.

Quantity
<div class="chi-form__item">
  <chi-label for="example__error">Quantity</chi-label>
  <chi-number-input id="example__error" inputstyle="danger" helper-message="Please enter a quantity"></chi-number-input>
</div>
This HTML Blueprint requires JavaScript. You may use your own solution, or use Chi's vanilla JavaScript solution, Chi.js.
<div class="chi-form__item">
  <label class="chi-label" for="example__error">Quantity</label>
  <div class="chi-number-input">
    <input id="example__error" type="number" class="chi-input -danger" value="0" aria-label="Quantity">
    <button aria-label="Decrease"></button>
    <button aria-label="Increase"></button>
  </div>
  <div class="chi-label -status -danger">
    <i class="chi-icon icon-circle-warning" aria-hidden="true"></i>
    Please enter a quantity
  </div>
</div>

<script>chi.numberInput(document.getElementById('example__error'));</script>

Sizes

Number inputs support the following sizes: xs, sm, md, lg, xl. The default size is md.

Label
Label
Label
Label
Label
<!-- xs -->
<div class="chi-form__item">
  <chi-label for="example__size-xs">Label</chi-label>
  <chi-number-input size="xs" id="example__size-xs"></chi-number-input>
</div>

<!-- sm -->
<div class="chi-form__item">
  <chi-label for="example__size-sm">Label</chi-label>
  <chi-number-input size="sm" id="example__size-sm"></chi-number-input>
</div>

<!-- md -->
<div class="chi-form__item">
  <chi-label for="example__size-md">Label</chi-label>
  <chi-number-input size="md" id="example__size-md"></chi-number-input>
</div>

<!-- lg -->
<div class="chi-form__item">
  <chi-label for="example__size-lg">Label</chi-label>
  <chi-number-input size="lg" id="example__size-lg"></chi-number-input>
</div>

<!-- xl -->
<div class="chi-form__item">
  <chi-label for="example__size-xl">Label</chi-label>
  <chi-number-input size="xl" id="example__size-xl"></chi-number-input>
</div>
This HTML Blueprint requires JavaScript. You may use your own solution, or use Chi's vanilla JavaScript solution, Chi.js.
<!-- xs -->
<div class="chi-form__item">
  <label class="chi-label" for="example__size-xs">Label</label>
  <div class="chi-number-input -xs">
    <input id="example__size-xs" type="number" class="chi-input" value="0" aria-label="Input Label">
    <button aria-label="Decrease"></button>
    <button aria-label="Increase"></button>
  </div>
</div>
<script>chi.numberInput(document.getElementById('example__size-xs'));</script>

<!-- sm -->
<div class="chi-form__item">
  <label class="chi-label" for="example__size-sm">Label</label>
  <div class="chi-number-input -sm">
    <input id="example__size-sm" type="number" class="chi-input" value="0" aria-label="Input Label">
    <button aria-label="Decrease"></button>
    <button aria-label="Increase"></button>
  </div>
</div>
<script>chi.numberInput(document.getElementById('example__size-sm'));</script>

<!-- md -->
<div class="chi-form__item">
  <label class="chi-label" for="example__size-md">Label</label>
  <div class="chi-number-input -md">
    <input id="example__size-md" type="number" class="chi-input" value="0" aria-label="Input Label">
    <button aria-label="Decrease"></button>
    <button aria-label="Increase"></button>
  </div>
</div>
<script>chi.numberInput(document.getElementById('example__size-md'));</script>

<!-- lg -->
<div class="chi-form__item">
  <label class="chi-label" for="example__size-lg">Label</label>
  <div class="chi-number-input -lg">
    <input id="example__size-lg" type="number" class="chi-input" value="0" aria-label="Input Label">
    <button aria-label="Decrease"></button>
    <button aria-label="Increase"></button>
  </div>
</div>
<script>chi.numberInput(document.getElementById('example__size-lg'));</script>

<!-- xl -->
<div class="chi-form__item">
  <label class="chi-label" for="example__size-xl">Label</label>
  <div class="chi-number-input -xl">
    <input id="example__size-xl" type="number" class="chi-input" value="0" aria-label="Input Label">
    <button aria-label="Decrease"></button>
    <button aria-label="Increase"></button>
  </div>
</div>
<script>chi.numberInput(document.getElementById('example__size-xl'));</script>

Sizes

Number inputs support the following sizes: xs, sm, md, lg. The default size is md.

Label
Label
Label
Label
<!-- xs -->
<div class="chi-form__item">
  <chi-label for="example__size-xs">Label</chi-label>
  <chi-number-input size="xs" id="example__size-xs"></chi-number-input>
</div>

<!-- sm -->
<div class="chi-form__item">
  <chi-label for="example__size-sm">Label</chi-label>
  <chi-number-input size="sm" id="example__size-sm"></chi-number-input>
</div>

<!-- md -->
<div class="chi-form__item">
  <chi-label for="example__size-md">Label</chi-label>
  <chi-number-input size="md" id="example__size-md"></chi-number-input>
</div>

<!-- lg -->
<div class="chi-form__item">
  <chi-label for="example__size-lg">Label</chi-label>
  <chi-number-input size="lg" id="example__size-lg"></chi-number-input>
</div>
This HTML Blueprint requires JavaScript. You may use your own solution, or use Chi's vanilla JavaScript solution, Chi.js.
<!-- xs -->
<div class="chi-form__item">
  <label class="chi-label" for="example__size-xs">Label</label>
  <div class="chi-number-input -xs">
    <input id="example__size-xs" type="number" class="chi-input" value="0" aria-label="Input Label">
    <button aria-label="Decrease"></button>
    <button aria-label="Increase"></button>
  </div>
</div>
<script>chi.numberInput(document.getElementById('example__size-xs'));</script>

<!-- sm -->
<div class="chi-form__item">
  <label class="chi-label" for="example__size-sm">Label</label>
  <div class="chi-number-input -sm">
    <input id="example__size-sm" type="number" class="chi-input" value="0" aria-label="Input Label">
    <button aria-label="Decrease"></button>
    <button aria-label="Increase"></button>
  </div>
</div>
<script>chi.numberInput(document.getElementById('example__size-sm'));</script>

<!-- md -->
<div class="chi-form__item">
  <label class="chi-label" for="example__size-md">Label</label>
  <div class="chi-number-input -md">
    <input id="example__size-md" type="number" class="chi-input" value="0" aria-label="Input Label">
    <button aria-label="Decrease"></button>
    <button aria-label="Increase"></button>
  </div>
</div>
<script>chi.numberInput(document.getElementById('example__size-md'));</script>

<!-- lg -->
<div class="chi-form__item">
  <label class="chi-label" for="example__size-lg">Label</label>
  <div class="chi-number-input -lg">
    <input id="example__size-lg" type="number" class="chi-input" value="0" aria-label="Input Label">
    <button aria-label="Decrease"></button>
    <button aria-label="Increase"></button>
  </div>
</div>
<script>chi.numberInput(document.getElementById('example__size-lg'));</script>

Expanded version

Base

Label
<div class="chi-form__item">
  <chi-label for="example__expanded-base">Label</chi-label>
  <chi-number-input expanded id="example__expanded-base"></chi-number-input>
</div>
This HTML Blueprint requires JavaScript. You may use your own solution, or use Chi's vanilla JavaScript solution, Chi.js.
<div class="chi-form__item">
  <label class="chi-label" for="example__expanded-base">Label</label>
  <div class="chi-number-input -expanded">
    <input id="example__expanded-base" class="chi-input" type="number" value="0" aria-label="Input Label">
    <button class="chi-button -icon" aria-label="Decrease">
      <div class="chi-button__content">
        <i class="chi-icon icon-minus" aria-hidden="true"></i>
      </div>
    </button>
    <button class="chi-button -icon" aria-label="Increase">
      <div class="chi-button__content">
        <i class="chi-icon icon-plus" aria-hidden="true"></i>
      </div>
    </button>
  </div>
</div>

<script>chi.numberInput(document.getElementById('example__expanded-base'));</script>

Disabled

Use the disabled boolean attribute to prevent users from interacting with an input. Disabled inputs are not submitted with the form and can not receive any browsing events such as mouse clicks or focus. Note: The required attribute can not be used on inputs with a disabled attribute specified.

Label
<div class="chi-form__item">
  <chi-label for="example__expanded-disabled">Label</chi-label>
  <chi-number-input expanded disabled id="example__expanded-disabled"></chi-number-input>
</div>
This HTML Blueprint requires JavaScript. You may use your own solution, or use Chi's vanilla JavaScript solution, Chi.js.
<div class="chi-form__item">
  <label class="chi-label" for="example__expanded-disabled">Label</label>
  <div class="chi-number-input -expanded">
    <input id="example__expanded-disabled" class="chi-input" type="number" value="0" aria-label="Input Label" disabled>
    <button class="chi-button -icon" aria-label="Decrease">
      <div class="chi-button__content">
        <i class="chi-icon icon-minus" aria-hidden="true"></i>
      </div>
    </button>
    <button class="chi-button -icon" aria-label="Increase">
      <div class="chi-button__content">
        <i class="chi-icon icon-plus" aria-hidden="true"></i>
      </div>
    </button>
  </div>
</div>

<script>chi.numberInput(document.getElementById('example__expanded-disabled'));</script>

Min/Max/Step

Use the min and max attributes to define minimum and maximum values on number inputs. Use the step attribute to indicate the expected granularity.

This example only accepts values between 0 and 6, and as the step is 2 and initial value is 1, only odd values are valid. Use the chiNumberInvalid event described in the events section to check if the entered value is valid.

Label
<div class="chi-form__item">
  <chi-label for="example__expanded-mms">Label</chi-label>
  <chi-number-input expanded id="example__expanded-mms" min="1" max="6" step="2" value="1"></chi-number-input>
</div>
This HTML Blueprint requires JavaScript. You may use your own solution, or use Chi's vanilla JavaScript solution, Chi.js.
<div class="chi-form__item">
  <label class="chi-label" for="example__expanded-mms">Label</label>
  <div class="chi-number-input -expanded">
    <input id="example__expanded-mms" class="chi-input" type="number" min="0" max="6" "step="2" value="1" aria-label="Input Label">
    <button class="chi-button -icon" aria-label="Decrease">
      <div class="chi-button__content">
        <i class="chi-icon icon-minus" aria-hidden="true"></i>
      </div>
    </button>
    <button class="chi-button -icon" aria-label="Increase">
      <div class="chi-button__content">
        <i class="chi-icon icon-plus" aria-hidden="true"></i>
      </div>
    </button>
  </div>
</div>

<script>
  chi.numberInput(
    document.getElementById('example__expanded-mms'),
    {autofix: true}
  );
</script>

Error

Use danger to provide feedback to users when input data fails to validate. To meet accessibility requirements, danger inputs must include an error message explaining the failure and/or how to correct it.

Quantity
<div class="chi-form__item">
  <chi-label for="example__expanded-error">Quantity</chi-label>
  <chi-number-input expanded id="example__expanded-error" inputstyle="danger" helper-message="Please enter a quantity"></chi-number-input>
</div>
This HTML Blueprint requires JavaScript. You may use your own solution, or use Chi's vanilla JavaScript solution, Chi.js.
<div class="chi-form__item">
  <label class="chi-label" for="example__expanded-error">Label</label>
  <div class="chi-number-input -expanded">
    <input id="example__expanded-error" class="chi-input -danger" type="number" value="0" aria-label="Input Label">
    <button class="chi-button -icon" aria-label="Decrease">
      <div class="chi-button__content">
        <i class="chi-icon icon-minus" aria-hidden="true"></i>
      </div>
    </button>
    <button class="chi-button -icon" aria-label="Increase">
      <div class="chi-button__content">
        <i class="chi-icon icon-plus" aria-hidden="true"></i>
      </div>
    </button>
  </div>
  <div class="chi-label -status -danger">
    <i class="chi-icon icon-circle-warning" aria-hidden="true"></i>
    Please enter a quantity
  </div>
</div>

<script>chi.numberInput(document.getElementById('example__expanded-error'));</script>

Sizes

Expanded number inputs support the following sizes: xs, sm, md, lg, xl. The default size is md.

Label
Label
Label
Label
Label
<!-- xs -->
<div class="chi-form__item">
  <chi-label for="example__expanded-size-xs">Label</chi-label>
  <chi-number-input expanded size="xs" id="example__expanded-size-xs"></chi-number-input>
</div>

<!-- sm -->
<div class="chi-form__item">
  <chi-label for="example__expanded-size-sm">Label</chi-label>
  <chi-number-input expanded size="sm" id="example__expanded-size-sm"></chi-number-input>
</div>

<!-- md -->
<div class="chi-form__item">
  <chi-label for="example__expanded-size-md">Label</chi-label>
  <chi-number-input expanded size="md" id="example__expanded-size-md"></chi-number-input>
</div>

<!-- lg -->
<div class="chi-form__item">
  <chi-label for="example__expanded-size-lg">Label</chi-label>
  <chi-number-input expanded size="lg" id="example__expanded-size-lg"></chi-number-input>
</div>

<!-- xl -->
<div class="chi-form__item">
  <chi-label for="example__expanded-size-xl">Label</chi-label>
  <chi-number-input expanded size="xl" id="example__expanded-size-xl"></chi-number-input>
</div>
This HTML Blueprint requires JavaScript. You may use your own solution, or use Chi's vanilla JavaScript solution, Chi.js.
<!-- xs -->
<div class="chi-form__item">
  <label class="chi-label" for="example__expanded-size-xs">Label</label>
  <div class="chi-number-input -expanded -xs">
    <input id="example__expanded-size-xs" class="chi-input" type="number" value="0" aria-label="Input Label">
    <button class="chi-button -icon" aria-label="Decrease">
      <div class="chi-button__content"><i class="chi-icon icon-minus" aria-hidden="true"></i></div>
    </button>
    <button class="chi-button -icon" aria-label="Increase">
      <div class="chi-button__content"><i class="chi-icon icon-plus" aria-hidden="true"></i>
    </div>
    </button>
  </div>
</div>
<script>chi.numberInput(document.getElementById('example__expanded-size-xs'));</script>

<!-- sm -->
<div class="chi-form__item">
  <label class="chi-label" for="example__expanded-size-sm">Label</label>
  <div class="chi-number-input -expanded -sm">
    <input id="example__expanded-size-sm" class="chi-input" type="number" value="0" aria-label="Input Label">
    <button class="chi-button -icon" aria-label="Decrease">
      <div class="chi-button__content"><i class="chi-icon icon-minus" aria-hidden="true"></i></div>
    </button>
    <button class="chi-button -icon" aria-label="Increase">
      <div class="chi-button__content"><i class="chi-icon icon-plus" aria-hidden="true"></i>
    </div>
    </button>
  </div>
</div>
<script>chi.numberInput(document.getElementById('example__expanded-size-sm'));</script>

<!-- md -->
<div class="chi-form__item">
  <label class="chi-label" for="example__expanded-size-md">Label</label>
  <div class="chi-number-input -expanded -md">
    <input id="example__expanded-size-md" class="chi-input" type="number" value="0" aria-label="Input Label">
    <button class="chi-button -icon" aria-label="Decrease">
      <div class="chi-button__content"><i class="chi-icon icon-minus" aria-hidden="true"></i></div>
    </button>
    <button class="chi-button -icon" aria-label="Increase">
      <div class="chi-button__content"><i class="chi-icon icon-plus" aria-hidden="true"></i></div>
    </button>
  </div>
</div>
<script>chi.numberInput(document.getElementById('example__expanded-size-md'));</script>

<!-- lg -->
<div class="chi-form__item">
  <label class="chi-label" for="example__expanded-size-lg">Label</label>
  <div class="chi-number-input -expanded -lg">
    <input id="example__expanded-size-lg" class="chi-input" type="number" value="0" aria-label="Input Label">
    <button class="chi-button -icon" aria-label="Decrease">
      <div class="chi-button__content"><i class="chi-icon icon-minus" aria-hidden="true"></i></div>
    </button>
    <button class="chi-button -icon" aria-label="Increase">
      <div class="chi-button__content"><i class="chi-icon icon-plus" aria-hidden="true"></i></div>
    </button>
  </div>
</div>
<script>chi.numberInput(document.getElementById('example__expanded-size-lg'));</script>

<!-- xl -->
<div class="chi-form__item">
  <label class="chi-label" for="example__expanded-size-xl">Label</label>
  <div class="chi-number-input -expanded -xl">
    <input id="example__expanded-size-xl" class="chi-input" type="number" value="0" aria-label="Input Label">
    <button class="chi-button -icon" aria-label="Decrease">
      <div class="chi-button__content"><i class="chi-icon icon-minus" aria-hidden="true"></i></div>
    </button>
    <button class="chi-button -icon" aria-label="Increase">
      <div class="chi-button__content"><i class="chi-icon icon-plus" aria-hidden="true"></i></div>
    </button>
  </div>
</div>
<script>chi.numberInput(document.getElementById('example__expanded-size-xl'));</script>

Sizes

Expanded number inputs support the following sizes: xs, sm, md, lg. The default size is md.

Label
Label
Label
Label
<!-- xs -->
<div class="chi-form__item">
  <chi-label for="example__expanded-size-xs">Label</chi-label>
  <chi-number-input expanded size="xs" id="example__expanded-size-xs"></chi-number-input>
</div>

<!-- sm -->
<div class="chi-form__item">
  <chi-label for="example__expanded-size-sm">Label</chi-label>
  <chi-number-input expanded size="sm" id="example__expanded-size-sm"></chi-number-input>
</div>

<!-- md -->
<div class="chi-form__item">
  <chi-label for="example__expanded-size-md">Label</chi-label>
  <chi-number-input expanded size="md" id="example__expanded-size-md"></chi-number-input>
</div>

<!-- lg -->
<div class="chi-form__item">
  <chi-label for="example__expanded-size-lg">Label</chi-label>
  <chi-number-input expanded size="lg" id="example__expanded-size-lg"></chi-number-input>
</div>
This HTML Blueprint requires JavaScript. You may use your own solution, or use Chi's vanilla JavaScript solution, Chi.js.
<!-- xs -->
<div class="chi-form__item">
  <label class="chi-label" for="example__expanded-size-xs">Label</label>
  <div class="chi-number-input -expanded -xs">
    <input id="example__expanded-size-xs" class="chi-input" type="number" value="0" aria-label="Input Label">
    <button class="chi-button -icon" aria-label="Decrease">
      <div class="chi-button__content"><i class="chi-icon icon-minus" aria-hidden="true"></i></div>
    </button>
    <button class="chi-button -icon" aria-label="Increase">
      <div class="chi-button__content"><i class="chi-icon icon-plus" aria-hidden="true"></i>
    </div>
    </button>
  </div>
</div>
<script>chi.numberInput(document.getElementById('example__expanded-size-xs'));</script>

<!-- sm -->
<div class="chi-form__item">
  <label class="chi-label" for="example__expanded-size-sm">Label</label>
  <div class="chi-number-input -expanded -sm">
    <input id="example__expanded-size-sm" class="chi-input" type="number" value="0" aria-label="Input Label">
    <button class="chi-button -icon" aria-label="Decrease">
      <div class="chi-button__content"><i class="chi-icon icon-minus" aria-hidden="true"></i></div>
    </button>
    <button class="chi-button -icon" aria-label="Increase">
      <div class="chi-button__content"><i class="chi-icon icon-plus" aria-hidden="true"></i>
    </div>
    </button>
  </div>
</div>
<script>chi.numberInput(document.getElementById('example__expanded-size-sm'));</script>

<!-- md -->
<div class="chi-form__item">
  <label class="chi-label" for="example__expanded-size-md">Label</label>
  <div class="chi-number-input -expanded -md">
    <input id="example__expanded-size-md" class="chi-input" type="number" value="0" aria-label="Input Label">
    <button class="chi-button -icon" aria-label="Decrease">
      <div class="chi-button__content"><i class="chi-icon icon-minus" aria-hidden="true"></i></div>
    </button>
    <button class="chi-button -icon" aria-label="Increase">
      <div class="chi-button__content"><i class="chi-icon icon-plus" aria-hidden="true"></i></div>
    </button>
  </div>
</div>
<script>chi.numberInput(document.getElementById('example__expanded-size-md'));</script>

<!-- lg -->
<div class="chi-form__item">
  <label class="chi-label" for="example__expanded-size-lg">Label</label>
  <div class="chi-number-input -expanded -lg">
    <input id="example__expanded-size-lg" class="chi-input" type="number" value="0" aria-label="Input Label">
    <button class="chi-button -icon" aria-label="Decrease">
      <div class="chi-button__content"><i class="chi-icon icon-minus" aria-hidden="true"></i></div>
    </button>
    <button class="chi-button -icon" aria-label="Increase">
      <div class="chi-button__content"><i class="chi-icon icon-plus" aria-hidden="true"></i></div>
    </button>
  </div>
</div>
<script>chi.numberInput(document.getElementById('example__expanded-size-lg'));</script>

Web Component

Properties

Property
Attribute
Description
Type
Default
disabled
disabled
used to determine if component is disabled or not
boolean
undefined
expanded
expanded
used to set component's expanded mode
boolean
undefined
helperMessage
helper-message
To display an additional helper text message below the Number Input
string
undefined
inputstyle
inputstyle
used to provide an input style like 'danger'. Mostly used for testing purposes
"danger" | "success" | "warning"
undefined
max
max
used to set a maximum allowed value
number
undefined
min
min
used to set a minimum allowed value
number
undefined
preventValueMutation
prevent-value-mutation
If set, component value won't be updated by itself.
boolean
undefined
required
required
used to determine if component is required or not
boolean
undefined
size
size
used to determine component's size
string
undefined
state
state
used to provide an input state like 'hover' or 'focus'. Mostly used for testing purposes
string
undefined
step
step
used to set a step to indicate the expected granularity
number
1
value
value
used to hold the value of the number input
string
undefined

Events

Event
Description
Type
chiBlur
Triggered when the element has lost focus.
CustomEvent<any>
chiChange
Triggered when an alteration to the element's value is committed by the user
CustomEvent<string>
chiClick
Triggered when the user clicks on increment/decrement button.
CustomEvent<any>
chiFocus
Triggered when the user sets focus on the element.
CustomEvent<any>
chiInput
Triggered when the user changed the element's value but did not commit the change yet
CustomEvent<string>
chiNumberInvalid
Triggered when the element's value committed by the user is an invalid number
CustomEvent<void>

JavaScript

This component accepts options to configure its behavior.

Option
Default
Description
autofix
false
Fixes automatically values that are out of range of defined by max and min attributes, and any value that doesn't fit the granularity defined by step and the initial value

Preventing memory leaks

Input number components have a dispose function to free all resources attached to the element, such as event listeners and object data. You should call this method when you want to remove the component.

var elem = document.getElementById('input-number-1');
var inputNumberComponent = chi.numberInput(elem);
// do stuff
inputNumberComponent.dispose();

TipIt is safe to call the numberInput method more than once, as it will return any previously created number input component associated to the input.

var elem = document.getElementById('input-number-1');
var inputNumberComponent = chi.numberInput(elem);
var elem2 = document.getElementById('input-number-1');
var inputNumberComponent2 = chi.numberInput(elem2);
inputNumberComponent === inputNumberComponent2; // returns true

inputNumberComponent.dispose(); // Only have to do it once.

Accessibility

Keyboard Navigation

KeyFunction
TabMoves focus to the next focusable element.
Shift + TabMoves focus to the previous focusable element.
Up ArroworShift+Up ArrowIncreases the value.
Down ArroworShift+Down ArrowDecreases the value.
EnterSubmits the entered value.

For comprehensive details on keyboard support, refer to our Keyboard Control Guide.

Visit WebAIM for keyboard techniques.

Guidance for developers
  • Ensure simplicity since not all browsers handle multiple labels linked to the same form element correctly.
  • Label Usage: Assign a label to each input field and make sure the for="" attribute of the label matches the id="" of the corresponding input. Remember, each id must be unique on the page, and each form element should have only one associated label.
  • Indicating Required Fields: Clearly mark required fields using indicators like an asterisk (*) or descriptive text to make them easily identifiable.
  • Help Text: Incorporate help text for all form fields, especially those with constraints. This text should be programmatically associated with the input, for example, using aria-describedby. This is particularly important for masked fields.
  • Test compatibility with various screen readers (like JAWS, NVDA, or VoiceOver) to ensure the number input component is announced correctly. Options should be clearly read out when navigated.
  • Error Validation: Fields with validation errors should use aria-describedby to ensure that error messages are accessible to assistive technologies. If an error message has an id="my-error-message", the corresponding input should include aria-describedby="my-error-message"
Guidance for designers
  • Design with simplicity to accommodate all browsers, minimizing complexities that could hinder accessibility.
  • Obvious Required Fields: Use visual cues, such as an asterisk (*) or supplementary text, to clearly mark required fields and make them easily distinguishable.
  • User-Friendly Help Text: Place help text or examples directly below or inside the number input field to guide users on the correct format.
  • Visible Error Feedback: Design error messages to appear clearly near the number input field when validation fails, using color, icons, or text to make them noticeable.
  • Sufficient Tap Targets: Ensure number input fields have large enough tap targets to accommodate users with different levels of dexterity, following touch-friendly design principles.
  • Use spacing, typography, and visual cues effectively.
  • Maintain consistency in the design of the number input to provide a cohesive user experience.

Find live examples of accessible inputs with different types in DigitalA11y project.

Resources

Other recommendations

Explore additional accessibility tips in the general Accessibility Guide.

WCAG 2.2 Guidelines

  • Non-text Content: All non-text content that is presented to the user has a text alternative that serves the equivalent purpose. (Level A)
  • Info and Relationships: Information, structure, and relationships conveyed through presentation can be programmatically determined or are available in text. (Level A)
  • Headings and Labels: Headings and labels describe topic or purpose. (Level AA)
  • Labels or Instructions: Labels or instructions are provided when content requires user input. (Level A)
  • Name, Role, Value: For all user interface components (including but not limited to: form elements, links and components generated by scripts), the name and role can be programmatically determined; states, properties, and values that can be set by the user can be programmatically set; and notification of changes to these items is available to user agents, including assistive technologies. (Level A)