You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@zag-js/pin-input

Package Overview
Dependencies
Maintainers
1
Versions
1120
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zag-js/pin-input

Core logic for the pin-input widget implemented as a state machine

1.21.1
latest
Source
npmnpm
Version published
Weekly downloads
294K
-12.66%
Maintainers
1
Weekly downloads
 
Created

What is @zag-js/pin-input?

@zag-js/pin-input is a package that provides a set of utilities to create accessible and customizable pin input components. It is part of the Zag.js library, which focuses on building state machines for UI components. This package allows developers to easily implement pin input fields with features like validation, focus management, and more.

What are @zag-js/pin-input's main functionalities?

Basic Pin Input Setup

This code demonstrates how to set up a basic pin input component using the @zag-js/pin-input package. It uses the `usePinInput` hook to manage the state and behavior of the pin input fields. The `getInputProps` function is used to spread the necessary props onto each input element, ensuring they are correctly managed.

import { usePinInput } from '@zag-js/pin-input';

const PinInputComponent = () => {
  const { inputProps, getInputProps } = usePinInput({
    id: 'pin-input',
    onComplete: (value) => console.log('Pin complete:', value),
  });

  return (
    <div>
      <input {...getInputProps({ index: 0 })} />
      <input {...getInputProps({ index: 1 })} />
      <input {...getInputProps({ index: 2 })} />
      <input {...getInputProps({ index: 3 })} />
    </div>
  );
};

Custom Validation

This example shows how to implement custom validation logic in a pin input component. The `validate` function checks if the entered pin is exactly 4 digits long and consists only of numbers. The `onComplete` callback is triggered when a valid pin is entered.

import { usePinInput } from '@zag-js/pin-input';

const PinInputWithValidation = () => {
  const { inputProps, getInputProps } = usePinInput({
    id: 'pin-input',
    validate: (value) => value.length === 4 && !isNaN(Number(value)),
    onComplete: (value) => console.log('Valid pin:', value),
  });

  return (
    <div>
      <input {...getInputProps({ index: 0 })} />
      <input {...getInputProps({ index: 1 })} />
      <input {...getInputProps({ index: 2 })} />
      <input {...getInputProps({ index: 3 })} />
    </div>
  );
};

Other packages similar to @zag-js/pin-input

Keywords

js

FAQs

Package last updated on 31 Jul 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.