🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

@sentinel-password/react-components

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sentinel-password/react-components

Accessible, headless React components for @sentinel-password - password validation UI made simple

latest
Source
npmnpm
Version
1.3.3
Version published
Weekly downloads
5.3K
-14.91%
Maintainers
1
Weekly downloads
 
Created
Source

@sentinel-password/react-components

npm version TypeScript License: MIT

Accessible, headless React components for password validation, built on top of @sentinel-password/core.

Documentation | Interactive Playground | API Reference

Features

  • Headless & Unstyled - Bring your own styles
  • Designed for WCAG 2.1 AAA - Semantic HTML, ARIA live region, full keyboard support, useId()-linked label. Page-level conformance depends on the consumer's CSS (contrast) and surrounding markup — see Accessibility below.
  • Keyboard Navigation - Complete keyboard support
  • TypeScript - Full type safety
  • Lightweight - Minimal bundle size
  • Flexible - Controlled and uncontrolled modes
  • React 18 & 19 - Supports both React 18 and 19

Installation

@sentinel-password/core is a regular dependency of this package (not a peer), so installing @sentinel-password/react-components automatically pulls in core. You only need to add core explicitly if you're importing from it directly elsewhere in your app.

npm install @sentinel-password/react-components
# or
pnpm add @sentinel-password/react-components
# or
yarn add @sentinel-password/react-components

Peer dependencies: React 18 or 19 and React DOM 18 or 19 — bring your own.

Quick Start

import { PasswordInput } from '@sentinel-password/react-components'

function MyForm() {
  return (
    <form>
      <PasswordInput
        label="Password"
        onValidationChange={(result) => {
          console.log('Valid:', result.valid)
          console.log('Strength:', result.strength)
        }}
      />
    </form>
  )
}

API Reference

PasswordInput

A headless password input component with built-in validation.

<PasswordInput
  label="Password"
  description="Enter a strong password"
  onValidationChange={(result) => console.log(result)}
  onChange={(value) => console.log(value)}
  showPassword={false}
  onShowPasswordChange={(show) => console.log(show)}
  validateOnMount={false}
  debounceMs={300}
/>

Props

PropTypeDefaultDescription
labelstringrequiredAccessible label rendered as <label>
descriptionstringHelper text linked via aria-describedby
valuestringControlled value. Any defined value flips the component to controlled mode — see the Controlled vs Uncontrolled rules.
defaultValuestringUncontrolled initial value. Silently ignored if value is defined.
onChange(value: string) => voidFired with the new string value (not the event)
onValidationChange(result: ValidationResult) => voidFired whenever validation completes
onShowPasswordChange(show: boolean) => voidFired when the show/hide toggle changes state
showPasswordbooleanuncontrolledControlled show/hide state — omit for uncontrolled toggle
validateOnMountbooleanfalseValidate the initial value once on mount — only if value/defaultValue is non-empty. Uses the debounced path; set debounceMs: 0 for synchronous mount validation.
validateOnChangebooleantrueValidate on every change (debounced). Set to false to disable change-driven validation.
debounceMsnumber300Debounce delay in milliseconds. 0 validates synchronously.
showValidationMessagesbooleantrueRender the validation messages <div role="alert">. Set to false to suppress the messages and render your own.
showToggleButtonbooleantrueRender the show/hide password button. Set to false to suppress (e.g., for a localized custom toggle).
validatorOptionsValidatorOptionsundefinedForwarded to every internal validatePassword(...) call. Covers minLength, requireUppercase, personalInfo, plus the v1.2.0 i18n options messages and formatMessage. Nested rather than spread because the prop type already extends React.InputHTMLAttributes<HTMLInputElement> (which defines minLength / maxLength as HTML attrs). Memoize this object if it contains closures — see the i18n guide.
toggleShowTextstring'Show'Visible button text when the password is hidden
toggleHideTextstring'Hide'Visible button text when the password is visible
toggleShowLabelstring'Show password'aria-label when hidden
toggleHideLabelstring'Hide password'aria-label when visible
containerClassNamestring''Class on the outer <div> wrapper
labelClassNamestring''Class on <label>
descriptionClassNamestring''Class on the description <div>
inputWrapperClassNamestring''Class on the <input> + toggle wrapper
toggleButtonClassNamestring''Class on the show/hide <button>
validationClassNamestring''Class on the validation messages <div>
className (and other standard input attrs)Forwarded to the underlying <input> (className, name, placeholder, autoFocus, etc.). See the "reserved" list below for the exceptions.

Most standard HTML input attributes are forwarded to the underlying <input> — for example name, placeholder, className, style, autoFocus, required, minLength, maxLength, pattern, inputMode, onFocus, onBlur, and data-*.

A handful are reserved by the component for its a11y and controlled-state internals — passing them is harmless but has no effect at runtime:

  • id — generated via useId() so the <label> can be associated correctly
  • aria-describedby / aria-invalid — managed for validation feedback
  • autoComplete — hardcoded to "new-password"
  • ref — not forwarded (the component is not wrapped in React.forwardRef)
  • type — toggled internally between "password" and "text"; omitted from the props type
  • onChange — replaced with the (value: string) => void signature documented above

onKeyDown is wrapped (the component handles Escape to clear the input, then calls your handler for all keys) rather than overridden.

See the API reference for the full table and the controlled-vs-uncontrolled rules.

Accessibility

The component is designed to meet WCAG 2.1 AAA criteria when integrated correctly. It provides:

  • Semantic HTML (<label htmlFor> linked to the input via useId())
  • ARIA attributes managed by the component: aria-invalid (true/omitted), aria-describedby, aria-pressed on the toggle button
  • A live region (role="alert" aria-live="polite" aria-atomic="true") that mounts only when there's feedback to announce
  • Keyboard support: Tab between input and toggle, Escape to clear the input, Space/Enter on the toggle button
  • Focus management for the input and toggle

The consumer is responsible for:

  • Color contrast — the component is headless, so CSS is yours. WCAG AAA requires 7:1 for normal text and 4.5:1 for large text.
  • Surrounding markup — heading structure, landmarks, form semantics, and overall page conformance.
  • Reduced-motion / forced-colors / focus-visible — these depend on your stylesheet.
  • Localization of toggle text — covered by toggleShowText / toggleHideText / toggleShowLabel / toggleHideLabel props (see below).

Internationalization

  • Validator messages — pass validatorOptions to forward messages / formatMessage (or any other ValidatorOptions field) into the component's underlying validatePassword calls. See the i18n guide for full examples.
  • Toggle button texttoggleShowText / toggleHideText set the visible button label; toggleShowLabel / toggleHideLabel set the aria-label. Defaults are 'Show' / 'Hide' / 'Show password' / 'Hide password'.

License

MIT © Aleksei Kankov

Keywords

password

FAQs

Package last updated on 19 Jun 2026

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