# Number Input

> A Number Input widget to allow user to enter numeric values

Number Input widgets are [Input Fields](https://golemui.com/dx/widgets-reference/input-fields/overview.md) that allow the user to enter numeric values. They can include built-in controls (plus/minus buttons) for incrementing and decrementing the number.


```ts title="number.ts"

export default [
  gui.inputs.numberInput('height', {
    label: 'Phone Number',
  }),
];
```

_Live demo on the docs page. Form definition: [number.ts](https://golemui.com/template/widgets-dx/number/number.ts)._

## Props

Use these `props` to customize your Number Input widget.

| prop           | type    | description                                                                          |
| -------------- | ------- | ------------------------------------------------------------------------------------ |
| `autocomplete` | string  | `'on'`, `'off'`, or a space-separated list of W3C autofill tokens                    |
| `autoGrow`     | boolean | If true, the input width expands according to the number of digits                   |
| `hint`         | string  | A description to display below the input                                             |
| `maximum`      | number  | The maximum allowed value                                                            |
| `minimum`      | number  | The minimum allowed value                                                            |
| `placeholder`  | string  | A placeholder text to display when the input has no value                            |
| `step`         | number  | The increment or decrement step size when using the plus/minus buttons or arrow keys |

### Placeholder

Use the property `placeholder` to add a placeholder.


```ts title="number.ts"

export default [
  gui.inputs.numberInput('height', {
    placeholder: '1.75',
    label: 'Height in meters',
  }),
];
```

_Live demo on the docs page. Form definition: [number-placeholder.ts](https://golemui.com/template/widgets-dx/number/number-placeholder.ts)._

### Hint

<Aside>A `label` is required for the `hint` to be displayed.</Aside>

Use the property `hint` to add a description.


```ts title="number.ts"

export default [
  gui.inputs.numberInput('number', {
    hint: 'This is a hint',
    placeholder: '555 0100',
    label: 'Phone Number',
  }),
];
```

_Live demo on the docs page. Form definition: [number-hint.ts](https://golemui.com/template/widgets-dx/number/number-hint.ts)._

### Step

Use the property `step` to define the amount by which the value increases or decreases when interacting with the controls.


```ts title="number.ts"

export default [
  gui.inputs.numberInput('height', {
    step: 0.01,
    label: 'Height in meters',
  }),
];
```

_Live demo on the docs page. Form definition: [number-step.ts](https://golemui.com/template/widgets-dx/number/number-step.ts)._

### Min & Max

Use the `minimum` and `maximum` properties to constrain the accepted range. The plus/minus buttons will be disabled if the limit is reached.


```ts title="number.ts"

export default [
  gui.inputs.numberInput('height', {
    placeholder: '0 to 2.5',
    minimum: 0,
    maximum: 2.5,
    label: 'Height in meters',
    validator: {
      minimum: 0,
      maximum: 2.5,
    },
  }),
];
```

_Live demo on the docs page. Form definition: [number-min-max.ts](https://golemui.com/template/widgets-dx/number/number-min-max.ts)._

### Auto Grow

Use the property `autoGrow` to allow the input's width to change dynamically based on its content value.


```ts title="number.ts"

export default [
  gui.inputs.numberInput('amount', {
    autoGrow: true,
    label: 'Amount',
  }),
];
```

_Live demo on the docs page. Form definition: [number-autogrow.ts](https://golemui.com/template/widgets-dx/number/number-autogrow.ts)._

## Styling

Number Inputs can be styled as explained in the [Styling Guide](https://golemui.com/dx/styling/overview.md).

### CSS Variables

Following you will find a list with the CSS Variables and a quick description of what you will style.

| CSS Variable             | Description                         |
| ------------------------ | ----------------------------------- |
| `--gui-radius-md`        | Overall widget border radius        |
| `--gui-border-default`   | Default border color                |
| `--gui-text-default`     | Default text and focus border color |
| `--gui-intent-error`     | Border color when invalid           |
| `--gui-space-gap--inner` | Label gap and margin bottom         |

### Anatomy

This is the anatomy of the Number Input Widget in case you want to use your CSS styles.


```html title="number-anatomy.html"
<gui-number-input class="gui-number gui-field">
  <gui-number class="gui-field">
    <label class="gui-label" for="fieldUid" id="fieldUid_label">
      <span class="gui-label__text">Label</span>
      <div class="gui-widget-hint" id="fieldUid_hint" aria-hidden="true">Hint</div>
    </label>

    <div class="gui-widget">
      <input
        type="number"
        inputmode="decimal"
        class="gui-widget-input"
        step="any"
        id="fieldUid"
        placeholder="Custom placeholder"
        aria-describedby="fieldUid_hint"
      />
      <span class="gui-number__decoration">
        <span class="gui-caret gui-caret--up" aria-hidden="true"></span>
        <span class="gui-caret" aria-hidden="true"></span>
      </span>
    </div>

    <div class="gui-validator gui-validator--empty" id="fieldUid_errors" role="alert"></div>
  </gui-number>
</gui-number-input>
```
