Examples
Examples
Basic Usage
A label will be displayed when provided via the label property.
Help Text & Placeholder
The help text and placeholder serve the purpose of guiding a user's input by providing additional information.
A help text provides more context as to why and how the data that is requested is relevant whereas a placeholder showcases an example of how data should be entered.
A help text can either be passed as an attribute for simple string-based content or via a slot for rich formatted content.
Required and Optional
Adding a required or optional label helps users to be guided while filling out a form. Usually, only Inputs that are an exception to the majority of other form fields in a form are marked as required or optional. For example, Inputs are marked as "Required" when the majority of the fields in the same form are optional and vice versa.
Icons
Icons can provide additional clarification on the content that should be entered.
States
The Input supports a wide range of different states.
Clearable
Marking an Input as clearable allows users to empty their value with a single click.
To define an accessible name for the clear button, the clear-aria-label can be used. In absence of one, the button will be rendered invisible accessibility-wise.
Validation
An Input's validity can either be determined automatically when used inside a form or can be controlled from outside based on custom rules and application business logic.
Inside a form
Inputs seamlessly integrate into a form's validation workflows and validate when a form is submitted. When no custom validation message is provided, the Input falls back to the browser's native validation message.
Inside an application
Inputs can be individually flagged as invalid based on custom rules or other business logic of an application. When flagged as invalid, an Input expects a descriptive validation message to be set alongside.
Listening to Events
The Input supports the most commonly used events.
💡 Did you know?
Some native events like change are blocked by the Shadow DOM boundary of the web component standard. Hence some of them are proxied through custom events.
Find out more: Form Input Events & API
Types
There is a wide variety of input types and control widgets available, depending on the device and user agent.Â
When not specified, the Input defaults to a type of "text".