Inputs collect data from the user.
Inputs collect data from the user.
Use the label attribute to give the input an accessible label. For labels that contain HTML, use the label slot instead.
Add descriptive help text to an input with the help-text attribute. For help texts that contain HTML, use the help-text slot instead.
Use the placeholder attribute to add a placeholder.
Use the maxlength and show-count-text attributes together to show a text counter while the user types into the input.
Use the required attribute to specify the input is a required field when using within a form.
Use the disabled attribute to disable an input.
Use the readonly attribute to make an input read-only.
Use the error-text attribute to customize the error message shown. Read more about error validation here .
Add the clearable attribute to add a clear button when the input has content.
Add the password-toggle attribute to add a toggle button that will show the password when activated.
You can listen for the ods-input event to determine when an input is updated. To see other input events check out the events below . You can also see how inputs are used in forms by checking out the form section .
import '@ods/components/web.input';Note: You only need to import a web component once in your code, as it registers itself globally when defined, allowing you to use it anywhere within your application without needing to re-import it each time you want to use the component.
This component is still in development and cannot be imported at this time.
| Name | Description |
|---|---|
| label | The input's label. Alternatively, you can use the `label` attribute. |
| prefix | Used to prepend a presentational icon or similar element to the input. |
| suffix | Used to append a presentational icon or similar element to the input. |
| clear-icon | An icon to use in lieu of the default clear icon. |
| show-password-icon | An icon to use in lieu of the default show password icon. |
| hide-password-icon | An icon to use in lieu of the default hide password icon. |
| help-text | Text that describes how to use the input. Alternatively, you can use the `help-text` attribute. |
Please note, both DOM properties and HTML attributes are shown in the table below. Unless otherwise specified, the property and attribute names are identical.
| Property/Attribute | Reflects | Type | Default |
|---|---|---|---|
title | string | '' | |
type | | 'date' | 'datetime-local' | 'email' | 'number' | 'password' | 'search' | 'tel' | 'text' | 'time' | 'url' | 'text' | |
name | string | '' | |
value | string | '' | |
defaultValue | string | '' | |
label | string | '' | |
helpText | string | '' | |
errorText | string | '' | |
showCountText | boolean | false | |
clearable | boolean | false | |
disabled | boolean | false | |
placeholder | string | '' | |
readonly | boolean | false | |
passwordToggle | boolean | false | |
passwordVisible | boolean | false | |
noSpinButtons | boolean | false | |
form | string | '' | |
required | boolean | false | |
pattern | string | ||
minlength | number | ||
maxlength | number | ||
min | number | string | ||
max | number | string | ||
step | number | 'any' | ||
autocapitalize | 'off' | 'none' | 'on' | 'sentences' | 'words' | 'characters' | ||
autocorrect | boolean | ||
autocomplete | 'on' | 'off' | 'off' | |
autofocus | boolean | ||
enterkeyhint | 'enter' | 'done' | 'go' | 'next' | 'previous' | 'search' | 'send' | ||
spellcheck | boolean | true | |
inputmode | 'none' | 'text' | 'decimal' | 'numeric' | 'tel' | 'search' | 'email' | 'url' | ||
valueAsDate | |||
valueAsNumber | |||
validity | |||
validationMessage |
| React Event | Description | Event Detail |
|---|---|---|
| ods-blur | Emitted when the control loses focus. | -- |
| ods-change | Emitted when an alteration to the control's value is committed by the user. | -- |
| ods-clear | Emitted when the clear button is activated. | -- |
| ods-focus | Emitted when the control gains focus. | -- |
| ods-input | Emitted when the control receives input. | -- |
| ods-invalid | Emitted when the form control has been checked for validity and its constraints aren't satisfied. | -- |
| Name | Description | Arguments |
|---|---|---|
| focus() | Sets focus on the input. | -- |
| blur() | Removes focus from the input. | -- |
| select() | Selects all the text in the input. | -- |
| setSelectionRange() | Sets the start and end positions of the text selection (0-based). | -- |
| setRangeText() | Replaces a range of text with a new string. | -- |
| showPicker() | Displays the browser picker for an input element (only works if the browser supports it for the input type). | -- |
| stepUp() | Increments the value of a numeric input type by the value of the step attribute. | -- |
| stepDown() | Decrements the value of a numeric input type by the value of the step attribute. | -- |
| checkValidity() | Checks for validity but does not show a validation message. Returns `true` when valid and `false` when invalid. | -- |
| getForm() | Gets the associated form, if one exists. | -- |
| reportValidity() | Checks for validity and shows the browser's validation message if the control is invalid. | -- |
| setCustomValidity() | Sets a custom validation message. Pass an empty string to restore validity. | -- |
| Name | Description |
|---|---|
| form-control | The form control that wraps the label, input, and help text. |
| form-control-label | The label's wrapper. |
| form-control-input | The input's wrapper. |
| form-control-help-text | The help text's wrapper. |
| form-control-error-text | The error text's wrapper. |
| base | The component's base wrapper. |
| input | The internal `<input>` control. |
| prefix | The container that wraps the prefix. |
| clear-button | The clear button. |
| password-toggle-button | The password toggle button. |
| suffix | The container that wraps the suffix. |
This component automatically imports the following dependencies.