Input

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.

Looking for a date picker? Check out our custom date picker component .

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.

Slots

NameDescription
labelThe input's label. Alternatively, you can use the `label` attribute.
prefixUsed to prepend a presentational icon or similar element to the input.
suffixUsed to append a presentational icon or similar element to the input.
clear-iconAn icon to use in lieu of the default clear icon.
show-password-iconAn icon to use in lieu of the default show password icon.
hide-password-iconAn icon to use in lieu of the default hide password icon.
help-textText that describes how to use the input. Alternatively, you can use the `help-text` attribute.

Properties

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/AttributeReflectsTypeDefault
title
string''
type
| 'date' | 'datetime-local' | 'email' | 'number' | 'password' | 'search' | 'tel' | 'text' | 'time' | 'url''text'
name
string''
value
string''
defaultValue
string''
label
string''
helpText
help-text
string''
errorText
error-text
string''
showCountText
show-count-text
booleanfalse
clearable
booleanfalse
disabled
booleanfalse
placeholder
string''
readonly
booleanfalse
passwordToggle
password-toggle
booleanfalse
passwordVisible
password-visible
booleanfalse
noSpinButtons
no-spin-buttons
booleanfalse
form
string''
required
booleanfalse
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
booleantrue
inputmode
'none' | 'text' | 'decimal' | 'numeric' | 'tel' | 'search' | 'email' | 'url'
valueAsDate
valueAsNumber
validity
validationMessage

Events

React EventDescriptionEvent Detail
ods-blurEmitted when the control loses focus.--
ods-changeEmitted when an alteration to the control's value is committed by the user.--
ods-clearEmitted when the clear button is activated.--
ods-focusEmitted when the control gains focus.--
ods-inputEmitted when the control receives input.--
ods-invalidEmitted when the form control has been checked for validity and its constraints aren't satisfied.--

Methods

NameDescriptionArguments
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.--

Parts

NameDescription
form-controlThe form control that wraps the label, input, and help text.
form-control-labelThe label's wrapper.
form-control-inputThe input's wrapper.
form-control-help-textThe help text's wrapper.
form-control-error-textThe error text's wrapper.
baseThe component's base wrapper.
inputThe internal `<input>` control.
prefixThe container that wraps the prefix.
clear-buttonThe clear button.
password-toggle-buttonThe password toggle button.
suffixThe container that wraps the suffix.

Dependencies

This component automatically imports the following dependencies.

  • ods-icon

Search