Number Input
<wa-number-input>
Number inputs allow users to enter and edit numeric values with optional stepper buttons.
<wa-number-input label="Quantity" value="1" style="max-width: 260px;"></wa-number-input>
This component works with standard <form> elements. Please refer to the section on form controls to learn more about form submission and client-side validation.
Examples
Jump to heading
Labels
Jump to heading
Use the label attribute to give the input an accessible label. For labels that contain HTML, use the label slot instead.
<wa-number-input label="How many items?" style="max-width: 260px;"></wa-number-input>
Hint
Jump to heading
Add descriptive hint to an input with the hint attribute. For hints that contain HTML, use the hint slot instead.
<wa-number-input label="Order quantity" hint="Enter the number of items you'd like to order" style="max-width: 260px;"></wa-number-input>
Placeholders
Jump to heading
Use the placeholder attribute to add a placeholder.
<wa-number-input placeholder="Enter a number" style="max-width: 260px;"></wa-number-input>
Setting Min, Max, and Step
Jump to heading
Use the min and max attributes to set a minimum and maximum value. Use the step attribute to change the granularity the value must adhere to when using the stepper buttons or arrow keys.
<wa-number-input label="Donation amount" hint="Amount in dollars (10-100, increments of 5)" min="10" max="100" step="5" value="25" style="max-width: 260px;" ></wa-number-input>
Appearance
Jump to heading
Use the appearance attribute to change the input's visual appearance.
<wa-number-input label="Outlined" appearance="outlined" value="42" style="max-width: 260px;"></wa-number-input> <br /> <wa-number-input label="Filled" appearance="filled" value="42" style="max-width: 260px;"></wa-number-input> <br /> <wa-number-input label="Filled Outlined" appearance="filled-outlined" value="42" style="max-width: 260px;"></wa-number-input>
Disabled
Jump to heading
Use the disabled attribute to disable an input.
<wa-number-input label="Disabled" value="100" disabled style="max-width: 260px;"></wa-number-input>
Readonly
Jump to heading
Use the readonly attribute to make the input readonly. The value can still be selected and copied, but it cannot be changed.
<wa-number-input label="Readonly" value="42" readonly style="max-width: 260px;"></wa-number-input>
Sizes
Jump to heading
Use the size attribute to change an input's size.
<wa-number-input label="Small" size="small" value="10" style="max-width: 260px;"></wa-number-input> <br /> <wa-number-input label="Medium" size="medium" value="20" style="max-width: 260px;"></wa-number-input> <br /> <wa-number-input label="Large" size="large" value="30" style="max-width: 260px;"></wa-number-input>
Pill
Jump to heading
Use the pill attribute to give inputs rounded edges.
<wa-number-input label="Small Pill" size="small" pill value="10" style="max-width: 260px;"></wa-number-input> <br /> <wa-number-input label="Medium Pill" size="medium" pill value="20" style="max-width: 260px;"></wa-number-input> <br /> <wa-number-input label="Large Pill" size="large" pill value="30" style="max-width: 260px;"></wa-number-input>
Without Steppers
Jump to heading
Add the without-steppers attribute to remove the increment/decrement buttons. Users can still modify the value using the keyboard.
<wa-number-input label="No steppers" value="50" without-steppers style="max-width: 260px;"></wa-number-input>
When steppers are hidden, users can still use the arrow keys to increment and decrement the value.
Start & End Decorations
Jump to heading
Use the start and end slots to add presentational elements like <wa-icon> within the input.
<wa-number-input label="Price" value="100" style="max-width: 260px;"> <wa-icon slot="start" name="dollar-sign" family="utility" variant="semibold"></wa-icon> </wa-number-input> <br /> <wa-number-input label="Weight (kg)" value="75" style="max-width: 260px;"> <wa-icon slot="end" name="bag-shopping" family="utility" variant="semibold"></wa-icon> </wa-number-input>
Custom Stepper Icons
Jump to heading
Use the increment-icon and decrement-icon slots to customize the stepper button icons.
<wa-number-input label="Custom icons" value="5" style="max-width: 260px;"> <wa-icon slot="increment-icon" name="plus" family="notdog-duo" variant="solid"></wa-icon> <wa-icon slot="decrement-icon" name="minus" family="notdog-duo" variant="solid"></wa-icon> </wa-number-input>
Customizing Label Position
Jump to heading
Use CSS parts to customize the way form controls are drawn. This example uses CSS grid to position the label to the left of the control, but the possible orientations are nearly endless. The same technique works for inputs, textareas, radio groups, and similar form controls.
<div class="label-on-left"> <wa-number-input label="Quantity" hint="How many do you need?" value="1"></wa-number-input> <wa-number-input label="Price" hint="Cost per unit" value="25"></wa-number-input> </div> <style> .label-on-left { display: grid; grid-template-columns: auto 1fr; gap: var(--wa-space-l); align-items: center; wa-number-input { grid-column: 1 / -1; grid-row-end: span 2; display: grid; grid-template-columns: subgrid; gap: 0 var(--wa-space-l); align-items: center; } ::part(label) { text-align: right; } ::part(hint) { grid-column: 2; } } </style>
Form Validation
Jump to heading
Use the required attribute to make the field required. Combine with min and max for range validation.
<form class="number-input-validation"> <wa-number-input name="quantity" label="Quantity" hint="Enter a value between 1 and 10" min="1" max="10" required style="max-width: 260px;" ></wa-number-input> <br /> <wa-number-input name="price" label="Price" hint="Must be a multiple of 0.25" min="0" step="0.25" required style="max-width: 260px;" ></wa-number-input> <br /> <wa-button type="submit" variant="brand">Submit</wa-button> <wa-button type="reset" variant="neutral">Reset</wa-button> </form> <script type="module"> const form = document.querySelector('.number-input-validation'); form.addEventListener('submit', event => { event.preventDefault(); // Log data to the console for the demo console.log(...new FormData(form)); }); </script>
Importing
Jump to heading
Autoloading components via projects is the recommended way to import components. If you prefer to do it manually, use one of the following code snippets.
Let your project code do the work! Sign up for free to use a project with your very own CDN — it's the fastest and easiest way to use Web Awesome.
To manually import this component from NPM, use the following code.
import '@awesome.me/webawesome/dist/components/number-input/number-input.js';
To manually import this component from React, use the following code.
import WaNumberInput from '@awesome.me/webawesome/dist/react/number-input';
Slots
Jump to heading
Learn more about using slots.
| Name | Description |
|---|---|
decrement-icon
|
An icon to use in lieu of the default decrement icon. |
end
|
An element, such as <wa-icon>, placed at the end of the input control (before steppers). |
hint
|
Text that describes how to use the input. Alternatively, you can use the hint attribute. |
increment-icon
|
An icon to use in lieu of the default increment icon. |
label
|
The input's label. Alternatively, you can use the label attribute. |
start
|
An element, such as <wa-icon>, placed at the start of the input control. |
Attributes & Properties
Jump to heading
Learn more about attributes and properties.
| Name | Description | Reflects | |
|---|---|---|---|
appearanceappearance |
The input's visual appearance.
Type
'filled' | 'outlined' | 'filled-outlined'Default
'outlined' |
|
|
autocompleteautocomplete |
Specifies what permission the browser has to provide assistance in filling out form field values. Refer to
this page on MDN for available values.
Type
string |
||
autofocusautofocus |
Indicates that the input should receive focus on page load.
Type
boolean |
||
defaultValuevalue |
The default value of the form control. Primarily used for resetting the form control.
Type
string | null |
|
|
enterkeyhintenterkeyhint |
Used to customize the label or icon of the Enter key on virtual keyboards.
Type
'enter' | 'done' | 'go' | 'next' | 'previous' | 'search' | 'send' |
||
hinthint |
The input's hint. If you need to display HTML, use the
hint slot instead.Type
stringDefault
'' |
||
inputmodeinputmode |
Tells the browser what type of data will be entered by the user, allowing it to display the appropriate virtual
keyboard on supportive devices.
Type
'numeric' | 'decimal'Default
'numeric' |
||
labellabel |
The input's label. If you need to display HTML, use the
label slot instead.Type
stringDefault
'' |
||
maxmax |
The input's maximum value.
Type
number |
||
minmin |
The input's minimum value.
Type
number |
||
pillpill |
Draws a pill-style input with rounded edges.
Type
booleanDefault
false |
|
|
placeholderplaceholder |
Placeholder text to show as a hint when the input is empty.
Type
stringDefault
'' |
||
readonlyreadonly |
Makes the input readonly.
Type
booleanDefault
false |
|
|
requiredrequired |
Makes the input a required field.
Type
booleanDefault
false |
|
|
sizesize |
The input's size.
Type
'small' | 'medium' | 'large'Default
'medium' |
|
|
stepstep |
Specifies the granularity that the value must adhere to, or the special value
any which means no stepping is
implied, allowing any numeric value.Type
number | 'any'Default
1 |
||
value |
The current value of the input, submitted as a name/value pair with form data.
|
||
withHintwith-hint |
Used for SSR. Will determine if the SSRed component will have the hint slot rendered on initial paint.
Type
booleanDefault
false |
||
withLabelwith-label |
Used for SSR. Will determine if the SSRed component will have the label slot rendered on initial paint.
Type
booleanDefault
false |
||
withoutStepperswithout-steppers |
Hides the increment/decrement stepper buttons.
Type
booleanDefault
false |
Methods
Jump to heading
Learn more about methods.
| Name | Description | Arguments |
|---|---|---|
blur() |
Removes focus from the input. | |
focus() |
Sets focus on the input. |
options: FocusOptions
|
select() |
Selects all the text in the input. | |
stepDown() |
Decrements the value by the step amount. | |
stepUp() |
Increments the value by the step amount. |
Events
Jump to heading
Learn more about events.
| Name | Description |
|---|---|
blur |
Emitted when the control loses focus. |
change |
Emitted when an alteration to the control's value is committed by the user. |
focus |
Emitted when the control gains focus. |
input |
Emitted when the control receives input. |
wa-invalid |
Emitted when the form control has been checked for validity and its constraints aren't satisfied. |
Custom States
Jump to heading
Learn more about custom states.
| Name | Description | CSS selector |
|---|---|---|
blank |
The input is empty. |
:state(blank)
|
focused |
The input has focus. |
:state(focused)
|
CSS parts
Jump to heading
Learn more about CSS parts.
| Name | Description | CSS selector |
|---|---|---|
base |
The wrapper containing the input and steppers. |
::part(base)
|
end |
The container that wraps the end slot. |
::part(end)
|
form-control-label |
Alias for the label element. |
::part(form-control-label)
|
hint |
The hint element. |
::part(hint)
|
input |
The internal <input> control. |
::part(input)
|
label |
The label element. |
::part(label)
|
start |
The container that wraps the start slot. |
::part(start)
|
stepper |
Both stepper buttons (for shared styling). |
::part(stepper)
|
stepper-decrement |
The decrement (-) button on the start side. |
::part(stepper-decrement)
|
stepper-increment |
The increment (+) button on the end side. |
::part(stepper-increment)
|
Dependencies
Jump to heading
This component automatically imports the following elements. Sub-dependencies, if any exist, will also be included in this list.