The code puncher component is a composable PIN/OTP input component designed for entering verification codes, PINs, and other short alphanumeric sequences. It provides a user-friendly interface with individual input slots, automatic navigation, paste support, and comprehensive keyboard controls. The component is ideal for two-factor authentication, PIN entry, license key input, and similar use cases where users need to enter structured codes.
✅ Use code puncher when:
- Collecting verification codes (OTP, SMS codes)
- Entering PIN numbers
- Inputting license keys or activation codes
- Building two-factor authentication flows
- Creating structured alphanumeric input fields
❌ Don't use code puncher for:
- Free-form text input (use input component)
- Multi-line text entry (use textarea)
- Numeric input with stepper controls (use number input)
- Single character input (use regular input)
- Long-form content (use textarea or rich text editor)
A basic 6-digit code puncher for OTP verification:
Provide contextual feedback to users with validation messages:
Choose code puncher sizes based on context and visual hierarchy:
Code puncher components support various states to communicate different conditions:
The code puncher supports different input patterns and masking for various use cases:
Code puncher components include comprehensive accessibility support for screen readers and keyboard navigation:
Many visual tweaks can be achieved by overriding the built-in CSS variables directly on the component instance:
The code puncher component exposes several CSS parts (base, slots, label, description, feedback) that can be targeted for deep customization:
The component automatically handles paste events, cleaning common separators and distributing characters User can paste "123-456" or "123 456" and it will be automaticallycleaned and distributed across slots Supports common separators: -, ·, and whitespace
Custom patterns can be specified using regex:
<!-- Numeric only (default) -->
<dap-ds-code-puncher pattern="[0-9]">
<!-- ... -->
</dap-ds-code-puncher>
<!-- Alphanumeric uppercase -->
<dap-ds-code-puncher pattern="[A-Z0-9]">
<!-- ... -->
</dap-ds-code-puncher>
<!-- Letters only -->
<dap-ds-code-puncher pattern="[A-Za-z]">
<!-- ... -->
</dap-ds-code-puncher>
Import the component by its own subpath. This registers <dap-ds-code-puncher> (and the
components it renders internally) and lets your bundler include only what you use:
import 'dap-design-system/components/code-puncher'
Need a reference to the class (e.g. to register it manually or extend it)? The same subpath default-exports it:
import DapDSCodePuncher from 'dap-design-system/components/code-puncher'
Register the whole library at once — convenient, but pulls every component into your bundle:
import 'dap-design-system'
import { DapDSCodePuncherReact } from 'dap-design-system/react'
| Property | Type | Default | Description |
|---|---|---|---|
mask | boolean | false | Mask input like password. Default is false. |
pattern | string | '[0-9]' | Regex pattern for allowed characters. Default is '[0-9]'. |
placeholder | string | '' | Placeholder character for empty slots. |
autocomplete | string | 'one-time-code' | Autocomplete hint. Default is 'one-time-code'. |
value | string | The complete code value. | |
size | 'xs', 'sm' , 'lg' | The size of the slots. Default is 'sm'. | |
label | string | The label of the component. | |
hideLabel | boolean | Visually hides the label while keeping it available to assistive technology. (default: false) | |
description | string | The description of the component. | |
tooltip | string | The tooltip of the component. | |
feedback | string | The feedback message. | |
feedbackType | 'negative', 'positive' , 'warning' | The feedback type. | |
status | 'success', 'error' | The status of the component. | |
disabled | boolean | Disable all slots. Default is false. | |
readonly | boolean | Read-only state. Default is false. | |
required | boolean | Required for form validation. Default is false. | |
requiredLabel | string | Indicator of required text. (default: '*') | |
name | string | Form element name. |
| Name | Description |
|---|---|
default | Slot for code-puncher-group, code-puncher-slot, and code-puncher-separator elements. |
| Event Name | Description | Type |
|---|---|---|
dds-input | Fires on each digit input. | {value: string, index: number } |
dds-change | Fires when value changes. | {value: string } |
dds-complete | Fires when all slots are filled. | {value: string } |
dds-focus | Fires when component gains focus. | void |
dds-blur | Fires when component loses focus. | void |
| Part Name | Description |
|---|---|
base | The main container. |
slots | The slots container. |
label | The label element. |
description | The description element. |
feedback | The feedback element. |
You can style CSS parts using the ::part() pseudo-element selector:
/* Target a specific part */
.my-custom-dap-ds-code-puncher::part(base) {
/* Your custom styles */
}
/* Target multiple parts */
.my-custom-dap-ds-code-puncher::part(base),
.my-custom-dap-ds-code-puncher::part(slots) {
/* Shared styles */
}
Example usage:
<dap-ds-code-puncher class="my-custom-dap-ds-code-puncher">
Code puncher
</dap-ds-code-puncher>
.my-custom-dap-ds-code-puncher::part(base) {
border-radius: 12px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
CSS parts allow you to style internal elements of the component while maintaining encapsulation. Learn more in our styling guide.
No CSS custom properties available.
| Property | Type | Default | Description |
|---|---|---|---|
mask | boolean | false | Mask input like password. Default is false. |
pattern | string | '[0-9]' | Regex pattern for allowed characters. Default is '[0-9]'. |
placeholder | string | '' | Placeholder character for empty slots. |
autocomplete | string | 'one-time-code' | Autocomplete hint. Default is 'one-time-code'. |
value | string | The complete code value. | |
size | 'xs', 'sm' , 'lg' | The size of the slots. Default is 'sm'. | |
label | string | The label of the component. | |
hideLabel | boolean | Visually hides the label while keeping it available to assistive technology. (default: false) | |
description | string | The description of the component. | |
tooltip | string | The tooltip of the component. | |
feedback | string | The feedback message. | |
feedbackType | 'negative', 'positive' , 'warning' | The feedback type. | |
status | 'success', 'error' | The status of the component. | |
disabled | boolean | Disable all slots. Default is false. | |
readonly | boolean | Read-only state. Default is false. | |
required | boolean | Required for form validation. Default is false. | |
requiredLabel | string | Indicator of required text. (default: '*') | |
name | string | Form element name. |
| Name | Description |
|---|---|
default | Slot for code-puncher-group, code-puncher-slot, and code-puncher-separator elements. |
| Event Name | Description | Type |
|---|---|---|
dds-input | Fires on each digit input. | {value: string, index: number } |
dds-change | Fires when value changes. | {value: string } |
dds-complete | Fires when all slots are filled. | {value: string } |
dds-focus | Fires when component gains focus. | void |
dds-blur | Fires when component loses focus. | void |
| Part Name | Description |
|---|---|
base | The main container. |
slots | The slots container. |
label | The label element. |
description | The description element. |
feedback | The feedback element. |
No CSS custom properties available.