One-time code
Material Design 3 text field web components: lit-material-text-field (single-line) and lit-material-textarea (multi-line) — filled + outlined, validation states.
- 11.0 KB gzipped
- @lit-material/text-field 1.8.0
- Renders on the server
Example
One-time code
The digits from a sign-in mail, an authenticator app or a text message. One native input sits under the boxes, so paste, deleting, the phone's code suggestion and screen readers work as in any field. Spaces and dashes in a pasted code are dropped, and complete fires when the last character is in.
<lit-material-one-time-code label="Code from the email" length="6" group-size="3"></lit-material-one-time-code>
Verify on complete
Install
npm install @lit-material/text-field @lit-material/tokens
import "@lit-material/text-field/one-time-code.js";
Link @lit-material/tokens/css/index.css once per page for the colour, type and shape tokens. Install guide
API
<lit-material-one-time-code>
A one-time code: the digits from a sign-in or confirmation mail, an
authenticator app or a text message. One native input underneath a row of
boxes, so typing, paste, deleting, the phone's code suggestion
(autocomplete="one-time-code") and screen readers all work as in a plain
field. Spaces and dashes in a pasted code are dropped.
Properties
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
value | value | string | "" | The code typed so far. |
length | length | number | 6 | How many characters the code has. |
alphanumeric | alphanumeric | boolean | false | Letters as well as digits (upper-cased as typed). Digits only by default. |
groupSize | group-size | number | 0 | A small gap after this many boxes, e.g. 3 for "123 456". 0 for none. |
label | label | string | "" | Visible label above the boxes. |
supportingText | supporting-text | string | "" | > |
errorText | error-text | string | "" | > |
error | error | boolean | false | > |
disabled | disabled | boolean | false | > |
required | required | boolean | false | > |
name | name | string | "" | > |
Events
| Event | Description |
|---|---|
complete | When the last character is entered; detail is { value }. Submit or verify here. |
input | Bubbles while the code is typed. |
CSS parts
| Part | Description |
|---|---|
cells | The row of boxes. |
cell | Each box. |
supporting | The supporting or error text. |