Number Input
import {NumberInputModule} from "@qualcomm-ui/angular/number-input"Overview
- This component implements the ARIA Spinbutton pattern. The
HomeandEndkeys work differently than a text input:Home: If the spinbutton has a minimum value, sets the value to its minimum.End: If the spinbutton has a maximum value, sets the value to its maximum.
- Template-driven and Reactive form values are supplied as numbers. When the field is cleared, the value is set to
NaN. You must account for this in your application logic.
Examples
Simple
The simple API bundles all subcomponents together into a single directive.
<q-number-input class="w-72" label="Label" placeholder="Enter a number" />Child Directives
Provide child directives to customize specific elements while keeping the simple API's default structure.
<q-number-input class="w-72" placeholder="Enter a number">
<label q-number-input-label>Label</label>
</q-number-input>Composite
Build with the composite API for granular control. This API requires you to provide each subcomponent, but gives you full control over the structure and layout.
<div class="w-72" q-number-input-root>
<label q-number-input-label>Label</label>
<div q-number-input-input-group>
<input placeholder="Enter a number" q-number-input-input />
<div q-number-input-control></div>
<span q-number-input-error-indicator></span>
</div>
<div q-number-input-error-text>Error</div>
</div>Min and Max values
Pass the min and max props to the root component to set the minimum and maximum values of the number input.
If the value entered is less than min or greater than max, it will be clamped to the nearest boundary on blur or enter.
<q-number-input class="w-72" defaultValue="7" max="10" min="5" />Step interval
Pass the step prop to the root component to set the increment or decrement step interval.
<q-number-input class="w-72" placeholder="Enter a number" step="3" />States
The following shows how the component appears in each interactive state.
<q-number-input disabled label="Disabled" placeholder="Disabled" />
<q-number-input label="Read only" placeholder="Read only" readOnly />
<q-number-input
errorText="Invalid"
invalid
label="Invalid"
placeholder="Invalid"
/>Sizes
Customize size using the size prop. The default size is md.
<q-number-input
class="w-56"
placeholder="sm"
size="sm"
startIcon="Sigma"
/>
<q-number-input
class="w-64"
placeholder="md"
size="md"
startIcon="Sigma"
/>
<q-number-input
class="w-72"
placeholder="lg"
size="lg"
startIcon="Sigma"
/>Error Text and Indicator
Error messages are displayed using two props:
The error text and indicator will only render when invalid is true.
Forms
Template Forms
When using template-driven forms with ngModel, perform validation manually in your component and pass the result to the invalid property.
TIP
Form validation timing is controlled by the updateOn property on the form control.
<q-number-input
class="w-72"
errorText="Value must be greater than 0"
label="Label"
placeholder="Enter a value"
[invalid]="isInvalid()"
[(ngModel)]="value"
/>Required
When using template forms, pass the required property to apply a validator to the form control.
<q-number-input
#textInput
class="w-72"
label="Required"
placeholder="Enter a value"
required
[(ngModel)]="value"
/>Reactive Forms
Use Reactive forms for better control of form state and validation.
State Guidelines
The disabled, invalid, and required properties have no effect when using Reactive Forms. Use the equivalent Reactive Form bindings instead:
disabledField = new FormControl(5)
invalidField = new FormControl(0, {
validators: [Validators.min(1)],
})
requiredField = new FormControl(5, {validators: [requiredNumberValidator]})
ngOnInit() {
this.disabledField.disable()
this.invalidField.markAsDirty()
}Composite API & Forms
When using the composite API with Reactive Forms, always apply form control bindings to the q-number-input-root directive.
API
<q-number-input>
The <q-number-input> component extends the q-number-input-root directive with the following properties:
| Prop | Type |
|---|---|
string | |
To customize the element, provide it using the directive instead:
<q-number-input> | |
Optional hint describing the element. This element is automatically
associated with the component's input element for accessibility. | string |
To customize the element, provide it using the directive instead:
<q-number-input> | |
Optional label describing the element. Recommended. This element is
automatically associated with the component's input element for
accessibility. | string |
To customize the element, provide it using the directive instead:
<q-number-input> | |
HTML placeholder attribute,
passed to the internal input element. | string |
string<q-number-input>
<div q-number-input-error-text>...</div>
</q-number-input>
string<q-number-input>
<div q-number-input-hint>...</div>
</q-number-input>
string<q-number-input>
<div q-number-input-label>...</div>
</q-number-input>
stringComposite API
q-number-input-root
| Prop | Type | Default |
|---|---|---|
Whether to allow mouse wheel to change the value | boolean | |
Whether to allow the value to overflow the min/max range | boolean | true |
Whether to clamp the value when the input loses focus (blur) | boolean | true |
The initial checked state of the checkbox when rendered. Use when you don't
need to control the checked state of the checkbox. This property will be
ignored if you opt into controlled state via form control bindings. | number | |
The document's text/writing direction. | 'ltr' | 'rtl' | "ltr" |
Controls whether the input is disabled in template-driven forms. When true,
prevents user interaction and applies visual styling to indicate the disabled
state. | boolean | |
lucide-angular icon, positioned after
the input. | | string | |
To customize the element, provide it using the directive instead: <div q-number-input-input-group> | ||
Whether to focus the input when the value changes | boolean | true |
The options to pass to the Intl.NumberFormat constructor | NumberFormatOptions | |
A root node to correctly resolve the Document in custom environments. i.e.,
Iframes, Electron. | () => | |
Hints at the type of data that might be entered by the user. It also determines
the type of keyboard shown to the user on mobile devices | | 'text' | "decimal" |
Controls the visual error state of the input. When true, applies semantic error
styling to indicate validation failure. | boolean | |
The current locale. Based on the BCP 47 definition. | string | 'en-US' |
The maximum value of the number input | number | Number.MAX_SAFE_INTEGER |
The minimum value of the number input | number | Number.MIN_SAFE_INTEGER |
The name of the input field in a checkbox. Useful for form submission. | string | |
The pattern used to check the element's value against | string | "[0-9]*(.[0-9]+)?" |
Whether the input is read-only. When true, prevents user interaction while
keeping the input focusable and visible. | boolean | |
Controls whether the input is required in template-driven forms. When
true, the input must have a value for form validation to pass. | boolean | |
The size of the input field and its elements. Governs properties like font
size, item padding, and icon sizes. | | 'sm' | 'md' |
Whether to spin the value when the increment/decrement button is pressed | boolean | true |
lucide-angular icon, positioned before
the input. | | string | |
To customize the element, provide it using the directive instead: <div q-number-input-input-group> | ||
Amount to increment/decrement the value when using stepper buttons or arrow keys. | number | 1 |
Specifies the localized strings that identify the accessibility elements and
their states | { | |
Event emitted when the checkbox is checked or unchecked. This is only emitted
on interaction. It doesn't emit in response to programmatic form control
changes. | { | |
Function invoked when the value overflows or underflows the min/max range | { | |
booleanbooleanbooleannumber'ltr' | 'rtl'
boolean| string
| LucideIconData
<div q-number-input-input-group>
<div q-input-end-icon [icon]="..."></div>
</div>
booleanNumberFormatOptionsIntl.NumberFormat constructor() =>
| Node
| ShadowRoot
| Document
| 'text'
| 'tel'
| 'numeric'
| 'decimal'
booleanstringnumbernumberstringstringbooleanboolean| 'sm'
| 'md'
| 'lg'
boolean| string
| LucideIconData
<div q-number-input-input-group>
<div q-input-start-icon [icon]="..."></div>
</div>
number{
decrementLabel?: string
incrementLabel?: string
valueText?: (
value: string,
) => string
}
{
value: string
valueAsNumber: number
}
{
reason:
| 'rangeUnderflow'
| 'rangeOverflow'
value: string
valueAsNumber: number
}
| Attribute / Property | Value |
|---|---|
class | 'qui-input__root' |
data-disabled | |
data-focus | |
data-invalid | |
data-part | 'root' |
data-scope | 'number-input' |
data-size | | 'sm' |
class'qui-input__root'data-disableddata-focusdata-invaliddata-part'root'data-scope'number-input'data-size| 'sm'
| 'md'
| 'lg'
q-number-input-input-group
NumberInputInputGroupComponent| Attribute / Property | Value |
|---|---|
class | 'qui-input__input-group' |
data-disabled | |
data-focus | |
data-invalid | |
data-part | 'input-group' |
data-readonly | |
data-scope | 'number-input' |
data-size | | 'sm' |
class'qui-input__input-group'data-disableddata-focusdata-invaliddata-part'input-group'data-readonlydata-scope'number-input'data-size| 'sm'
| 'md'
| 'lg'
q-number-input-label
NumberInputLabelComponent| Attribute / Property | Value |
|---|---|
class | 'qui-input__label' |
data-disabled | |
data-focus | |
data-invalid | |
data-part | 'label' |
data-scope | 'number-input' |
data-size | | 'sm' |
class'qui-input__label'data-disableddata-focusdata-invaliddata-part'label'data-scope'number-input'data-size| 'sm'
| 'md'
| 'lg'
q-number-input-hint
| Attribute / Property | Value |
|---|---|
class | 'qui-input__hint' |
data-disabled | |
data-part | 'hint' |
data-scope | 'number-input' |
class'qui-input__hint'data-disableddata-part'hint'data-scope'number-input'q-number-input-control
| Attribute / Property | Value |
|---|---|
class | 'qui-number-input__control' |
data-disabled | |
data-focus | |
data-invalid | |
data-part | 'control' |
data-scope | 'number-input' |
data-size | | 'sm' |
class'qui-number-input__control'data-disableddata-focusdata-invaliddata-part'control'data-scope'number-input'data-size| 'sm'
| 'md'
| 'lg'
q-number-input-decrement-trigger
NumberInputDecrementTriggerComponent| Attribute / Property | Value |
|---|---|
class | 'qui-number-input__step-trigger' |
data-disabled | |
data-part | 'decrement-trigger' |
data-scope | 'number-input' |
data-size | | 'sm' |
tabIndex | -1 |
class'qui-number-input__step-trigger'data-disableddata-part'decrement-trigger'data-scope'number-input'data-size| 'sm'
| 'md'
| 'lg'
tabIndex-1
q-number-input-increment-trigger
NumberInputIncrementTriggerComponent| Attribute / Property | Value |
|---|---|
class | 'qui-number-input__step-trigger' |
data-disabled | |
data-part | 'increment-trigger' |
data-scope | 'number-input' |
data-size | | 'sm' |
tabIndex | -1 |
class'qui-number-input__step-trigger'data-disableddata-part'increment-trigger'data-scope'number-input'data-size| 'sm'
| 'md'
| 'lg'
tabIndex-1
q-number-input-input
| Attribute / Property | Value |
|---|---|
class | 'qui-input__input' |
data-disabled | |
data-empty | |
data-invalid | |
data-part | 'input' |
data-scope | 'number-input' |
data-size | | 'sm' |
class'qui-input__input'data-disableddata-emptydata-invaliddata-part'input'data-scope'number-input'data-size| 'sm'
| 'md'
| 'lg'
q-number-input-error-text
| Attribute / Property | Value |
|---|---|
class | 'qui-input__error-text' |
data-part | 'error-text' |
data-scope | 'number-input' |
hidden | boolean |
class'qui-input__error-text'data-part'error-text'data-scope'number-input'hiddenbooleanq-number-input-error-indicator
NumberInputErrorIndicatorComponent| Attribute / Property | Value |
|---|---|
class | 'qui-input__error-indicator' |
data-part | 'error-indicator' |
data-scope | 'number-input' |
data-size | | 'sm' |
hidden | boolean |
class'qui-input__error-indicator'data-part'error-indicator'data-scope'number-input'data-size| 'sm'
| 'md'
| 'lg'
hiddenboolean