Allows users to input a sequence of one-character alphanumeric inputs.
The Input PIN component is a web component built from scratch to allow users to input a sequence of one-character alphanumeric inputs. This is particularly useful in scenarios such as:
To get started, simply use the <uk-input-pin> markup in your HTML code.
By default, the Input PIN component is set to accept 6 characters. However, you can easily customize this by adding the length attribute to the <uk-input-pin> element. Simply specify the desired length as a numerical value, and the component will automatically adjust to accommodate the specified number of inputs.
By default, the input fields in the Input PIN component are displayed adjacent to each other. To add visual separation between each input, simply add the separated attribute to the <uk-input-pin> element. This will add gaps between each input, making it easier for users to distinguish between individual characters.
To prevent user input, add the disabled attribute to the <uk-input-pin> element. This will disable all input fields, making it impossible for users to enter or modify the PIN sequence.
The Input PIN component is designed to integrate seamlessly with Franken UI. To indicate an error state in the form, simply add the error attribute. This will apply a “danger” state to the component, providing visual feedback to the user.
This field is required.
<div class="space-y-1.5">
<label class="uk-form-label uk-text-danger">PIN</label>
<div class="uk-form-controls">
<uk-input-pin error name="PIN" uk-cloak></uk-input-pin>
</div>
<p class="uk-form-help uk-text-danger">This field is required.</p>
</div> When loading Web Components, there may be a brief delay before the content is fully rendered. This can result in a flash of unstyled content or unprocessed templates. To mitigate this issue, add the uk-cloak attribute to hide the entire element until Franken WC has fully loaded on the page. For an even more polished experience, consider setting a predefined height on the parent element to prevent layout shift and ensure a smooth user experience.
<div class="h-9">
<uk-input-pin uk-cloak>...</uk-input-pin>
</div>
The following attributes are available for this component:
| Name | Type | Default | Description |
|---|---|---|---|
autofocus | Boolean | false | Automatically focuses on the first input field when the component is rendered. |
disabled | Boolean | false | Disables all input fields, making the entire component read-only. |
error | Boolean | false | Applies the uk-form-error class when set to true, indicating an error state in the form. |
length | String | 6 | Specifies the number of input fields, determining the length of the PIN sequence. |
name | String | Defines the name of the PIN input, allowing you to capture its value on your server. | |
separated | Boolean | false | Enables the separated input style, adding gaps between each input field. |
The Input PIN component triggers the following events on elements with this component attached:
| Name | Description |
|---|---|
uk-input-pin:input | Fired after the value has changed, providing an opportunity to respond to user input. |