
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
react-pin-field
Advanced tools
React component for entering PIN codes

Live demo available at https://soywod.github.io/react-pin-field/.
onchange native event with minimum interaction for better browser compatibilitydir left-to-right and right-to-leftautofocus by focusing either the first or the last input, depending on diraria-required, aria-label…npm install react-pin-field
import PinField from "react-pin-field";
// React PIN Field inherits native props from HTMLInputElement,
// except few event handlers that are overriden:
type NativeProps = Omit<
InputHTMLAttributes<HTMLInputElement>,
"onChange" | "onKeyDown" | "onCompositionStart" | "onCompositionEnd"
>;
type Props = NativeProps & {
length?: number;
format?: (char: string) => string;
formatAriaLabel?: (index: number, total: number) => string;
onChange?: (value: string) => void;
onComplete?: (value: string) => void;
};
lengthThe length of the PIN field, which represents the number of inputs.
Defaults to 5
formatCharacters can be formatted with any function of type (char: string) => string.
Defaults to identity function char => char
formatAriaLabelThis function is used to generate accessible labels for each input within the <PinField />. By default it renders the string PIN field 1 of 6, PIN field 2 of 6, etc., depending on the actual index of the input field and the total length of the pin field.
You can customize the aria-label string by passing your own function. This can be useful for: i) site internationalisation (i18n); ii) simply describing each input with different semantics than the ones provided by react-pin-field.
Defaults to (n, total) => "PIN field ${n} of ${total}"
onChangeThis function is called everytime the PIN field changes its value.
onCompleteThis function is called everytime the PIN field is completed. A PIN field is considered complete when:
required, pattern etc)React PIN Field exposes a special reference which is an array of HTMLInputElement:
const ref = useRef<HTMLInputElement[]>();
<PinField ref={ref} />;
// focus the third input
ref.current[2].focus();
React PIN Field can be styled either with style or className. This last one allows you to use pseudo-classes like :nth-of-type, :focus, :hover, :valid, :invalid…
By default, React PIN Field is an uncontrolled component, which means that its internal state cannot be changed. You can only listen to changes via onChange and onComplete.
To control the React PIN Field state, you can use the usePinField() custom hook:
const handler = usePinField();
// The handler exposes a value and setValue to control the PIN code,
// as well as a state and dispatch for advanced usage.
// Let know the PIN field that you want to use this custom state
// instead of its internal one.
return <PinField handler={handler} />
See the controlled section of the live demo.
See the Contributing guide.
If you appreciate the project, feel free to donate using one of the following providers:
FAQs
React component for entering PIN codes
The npm package react-pin-field receives a total of 12,285 weekly downloads. As such, react-pin-field popularity was classified as popular.
We found that react-pin-field demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.