Genesis
@experimental

PasswordToggleField

Password input with a show/hide toggle that keeps caret position and re-masks on submit. Wraps a Radix unstable_* export — API may change.

PasswordToggleField — a password input with a show/hide control that keeps focus and caret position across the toggle. Composition: ```tsx <PasswordToggleField> <PasswordToggleFieldInput placeholder="Password" /> <PasswordToggleFieldToggle> <PasswordToggleFieldSlot visible={<EyeOff />} hidden={<Eye />} /> </PasswordToggleFieldToggle> </PasswordToggleField> ``` Why Radix and not five lines of `useState` plus `type={shown ? "text" : "password"}`: the naive version loses the caret on every toggle, leaves the button unlabelled (or labelled with a state that never updates), and — the part nobody writes — leaves the password visible in the DOM after the form is submitted or reset. Radix resets visibility on both `submit` and `reset`, restores `selectionStart`/`selectionEnd` after the type swap, and derives the toggle's `aria-label` ("Show password" / "Hide password") from the current state unless the caller supplies text or a label of their own. Radix's own root is a **context provider with no DOM node of its own**, so this wrapper renders a `relative` box around the children. That box is load-bearing, not decoration: `PasswordToggleFieldToggle` is positioned `absolute`, and absolute positioning resolves against the nearest positioned ancestor. Without a wrapper the toggle would escape the field and land against whatever positioned ancestor the consumer's page happened to have — or the initial containing block, i.e. the page corner. The composition documented above would put the show/hide button nowhere near the input. --- **Stability.** Radix ships this primitive as `unstable_PasswordToggleField` and documents its API as subject to change; the underlying `@radix-ui/react-password-toggle-field` package is still on `0.1.x`. It is exported here under its stable-looking name for ergonomics, but it is the one component in this package whose props may change in a minor release. Pin the package if that is unacceptable, or compose `Input` + `Button` yourself.

packages/ui/src/components/ui/password-toggle-field.tsx

Import
Subpath export: @marktiderman/genesis-ui
import { PasswordToggleField } from "@marktiderman/genesis-ui";
Exports
Re-exported from @marktiderman/genesis-ui.
  • PasswordToggleField
  • PasswordToggleFieldInput
  • PasswordToggleFieldToggle
  • PasswordToggleFieldSlot
  • PasswordToggleFieldIcon
Components
Auto-generated from TypeScript source via react-docgen-typescript.

PasswordToggleField

PasswordToggleField — a password input with a show/hide control that keeps focus and caret position across the toggle. Composition: ```tsx <PasswordToggleField> <PasswordToggleFieldInput placeholder="Password" /> <PasswordToggleFieldToggle> <PasswordToggleFieldSlot visible={<EyeOff />} hidden={<Eye />} /> </PasswordToggleFieldToggle> </PasswordToggleField> ``` Why Radix and not five lines of `useState` plus `type={shown ? "text" : "password"}`: the naive version loses the caret on every toggle, leaves the button unlabelled (or labelled with a state that never updates), and — the part nobody writes — leaves the password visible in the DOM after the form is submitted or reset. Radix resets visibility on both `submit` and `reset`, restores `selectionStart`/`selectionEnd` after the type swap, and derives the toggle's `aria-label` ("Show password" / "Hide password") from the current state unless the caller supplies text or a label of their own. Radix's own root is a **context provider with no DOM node of its own**, so this wrapper renders a `relative` box around the children. That box is load-bearing, not decoration: `PasswordToggleFieldToggle` is positioned `absolute`, and absolute positioning resolves against the nearest positioned ancestor. Without a wrapper the toggle would escape the field and land against whatever positioned ancestor the consumer's page happened to have — or the initial containing block, i.e. the page corner. The composition documented above would put the show/hide button nowhere near the input. --- **Stability.** Radix ships this primitive as `unstable_PasswordToggleField` and documents its API as subject to change; the underlying `@radix-ui/react-password-toggle-field` package is still on `0.1.x`. It is exported here under its stable-looking name for ergonomics, but it is the one component in this package whose props may change in a minor release. Pin the package if that is unacceptable, or compose `Input` + `Button` yourself.

PropTypeDefaultDescription
classNamestring—Class names for the field wrapper (the positioned box, see below).
testIDstring—Stable test/automation selector for the wrapper (emitted as `data-testid`).

PasswordToggleFieldSlot

PasswordToggleFieldSlot — renders one of two nodes depending on visibility. Takes either the declarative pair (`visible` / `hidden`) or a `render` callback receiving `{ visible }`. Unstyled by design: it is a switch, not a box, and wrapping it in an element would break the toggle's `[&_svg]` icon sizing.

No declared props.

PasswordToggleFieldInput

PasswordToggleFieldInput — the field itself. Styling matches `Input`, with right padding reserved for the toggle so the button never sits on top of the text. Radix owns `type`, which is why it is absent from the props: it is derived from the field's visibility state and a caller-supplied value would fight it.

PropTypeDefaultDescription
asChildboolean—
testIDstring—Stable test/automation selector (emitted as `data-testid`).

PasswordToggleFieldToggle

PasswordToggleFieldToggle — the show/hide button. Positioned `absolute` against the `relative` box that `PasswordToggleField` renders — which is why that box exists; see the root's docs. Keep this component inside a `PasswordToggleField`: positioning it against an arbitrary ancestor is not a supported arrangement. Its accessible name comes from Radix ("Show password" / "Hide password", following the current state) unless you provide inner text or an `aria-label`.

PropTypeDefaultDescription
asChildboolean—
testIDstring—Stable test/automation selector (emitted as `data-testid`).

PasswordToggleFieldIcon

PasswordToggleFieldIcon — the SVG-level variant of `PasswordToggleFieldSlot`. Swaps the icon's inner content while keeping ONE `<svg>` element mounted, so a CSS transition on the glyph survives the toggle instead of being restarted by a remount.

PropTypeDefaultDescription
asChildboolean—