Skip to content

feat(PasswordInput): add a password field with a show/hide toggle - #173

Merged
agatha197 merged 6 commits into
mainfrom
feat/password-input
Nov 24, 2026
Merged

agatha197 merged 6 commits into
mainfrom
feat/password-input

Conversation

@agatha197

@agatha197 agatha197 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • New PasswordInput (@lablup/ui-common/PasswordInput, also from the root): a password field for Form.Item with a show/hide toggle. Source in src/components/PasswordInput/. It renders Astryx's TextInput under the same contract as ui-common's TextInput wrapper (useFormControl, useMergedValue, FormControlScope), so the item supplies label, value, status, disabled and the in-item width.
  • Props are TextInput's minus type, hasSpellCheck, hasAutoCorrect and autoCapitalize, which it owns, plus isRevealed / defaultIsRevealed / onRevealedChange (Astryx's isOpen / defaultIsOpen / onOpenChange naming) and showPasswordLabel / hidePasswordLabel.
  • The toggle is a ghost, small IconButton (lucide Eye / EyeOff) inside the field's trailing edge, coloured --color-text-secondary. TextInput has no end slot, so the root is a flex row and a negative margin pulls the toggle back over the control's edge, wherever the field's width puts it (unset, in-item 100%, or an explicit width). The control reserves --size-element-sm plus padding at its end, so a long password stops short of the button.
  • Mousedown on the toggle is prevented, so focus (and the touch keyboard) stays in the field. An Enter keydown on the toggle stops propagating, so it never submits the surrounding form.
  • Spellcheck, autocorrect and autocapitalize are off; input::-ms-reveal is hidden so Edge shows no second eye.
  • A disabled field is always masked and its toggle disabled. An uncontrolled one resets to masked during render when disabled turns on (prev-prop comparison, no effect), so it stays masked after re-enabling: a login form that disables its fields while submitting hides the password.
  • Strings: uic.PasswordInput.showPassword / hidePassword, translated in all 20 locale files.
  • Registered in exports.customs.json (with subpath) and regenerated with gen:exports; CLI doc astryx/components/PasswordInput.doc.mjs + stub; README, CONTRIBUTING component table, ui-common.doc.mjs; CHANGELOG.md ### Added under [Unreleased]. No version bump or codemod (additive).

Tests

  • PasswordInput.test.tsx: toggles type and accessible name both ways and reports onRevealedChange; defaultIsRevealed; controlled isRevealed; spellcheck/autocorrect/autocapitalize off; mousedown prevented and focus stays in the field; Enter on the toggle does not reach a parent <form> keydown handler while Enter in the field still does; disabling masks, disables the toggle and stays masked after re-enabling; controlled + disabled is masked; value and disabled through Form.Item / <Form disabled>; label overrides; Korean catalog name; stylesheet contract (reserved padding, ::-ms-reveal, secondary colour).
  • Added to the shared formControls.test.tsx table (label, error, required, disabled, onBlur validation, focusField, in-item width 100%, explicit width).
  • 8 stories with visual baselines (Default, Revealed, LongPassword, ControlledReveal, Statuses, Disabled, InFormItem, FormDisabled).

Verification

pnpm run verify passes (110 test files, 2387 passed / 16 skipped; integration validates with 0 errors, 0 warnings). pnpm run test:visual:docker src/components/PasswordInput passes with the new baselines.

Context

Consumer: lablup/backend.ai-webui#11278. The login form's prototype wrapper (lablup/backend.ai-webui#11280, closed) moved here; lablup/backend.ai-webui#11382 uses this component and is pinned to this PR's preview. Product: Backend.AI WebUI; the WebUI team does the move.

Risk tier: High — package.json
Suggested human approvals: 2 (branch protection decides)
Reviewed by fw ready gate at 63b8e5b (round 2)

PasswordInput is a Form.Item control on Astryx's TextInput, with TextInput's
props minus type, hasSpellCheck, hasAutoCorrect and autoCapitalize. A ghost
icon button sits inside the field's trailing edge in the secondary text
colour; the control reserves its room so a long password never runs under
it. The toggle keeps focus in the field on press, stops an Enter keydown
from reaching the form, and is named from uic.PasswordInput.showPassword /
hidePassword (overridable, translated in every locale). Spellcheck,
autocorrect and autocapitalize are off, and Edge's ::-ms-reveal is hidden.

The reveal state is uncontrolled (defaultIsRevealed) or controlled
(isRevealed, onRevealedChange). A disabled field is masked with its toggle
disabled; an uncontrolled one resets to masked during render on the change,
not in an effect.
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR

GitHub Pages may take up to a minute to hydrate after the deploy.

🧩 Changed Components

Component Changed Stories Open
PasswordInput new + stories 12 Storybook ↗
22 other changed file(s) in src/
  • src/i18n/catalog.ts
  • src/i18n/locales/de-DE.json
  • src/i18n/locales/el-GR.json
  • src/i18n/locales/es-ES.json
  • src/i18n/locales/fi-FI.json
  • src/i18n/locales/fr-FR.json
  • src/i18n/locales/id-ID.json
  • src/i18n/locales/it-IT.json
  • src/i18n/locales/ja-JP.json
  • src/i18n/locales/ko-KR.json
  • …and 12 more

📦 Bundle Size

Total gzip (JS + CSS): 213.7 kB

No base measurement — the merge-base build was skipped (a build input outside src/ changed, or the base build failed).


Generated by the PR Preview workflow for eabfc7e · Storybook · CI run

github-actions Bot added a commit that referenced this pull request Nov 23, 2026
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Preview published under the pr-173 dist-tag (npmjs): 0.2.0-alpha.21.pr-173-20261124004145-eabfc7e75

pnpm add @lablup/ui-common@0.2.0-alpha.21.pr-173-20261124004145-eabfc7e75
pnpm add -D @lablup/ui-common-cli@0.2.0-alpha.21.pr-173-20261124004145-eabfc7e75

In backend.ai-webui: pnpm run ui-common:pin pr-173. A consumer PR pinned to a preview cannot merge; repin to canary after this PR merges.

@agatha197

Copy link
Copy Markdown
Contributor Author

Consumer: lablup/backend.ai-webui#11382 uses PasswordInput for the login password field, pinned to this PR's preview.

github-actions Bot added a commit that referenced this pull request Nov 23, 2026

@agatha197 agatha197 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ready-gate agent review — 10 findings — 7 Important, 3 Nit, 0 Pre-existing. The summary comment on this PR lists every finding and its outcome.

@agatha197

agatha197 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor Author

2 findings — 2 Important, 0 Nit, 0 Pre-existing

Round 2 — 63b8e5b

# Tag File:line Finding Outcome
1 Important src/components/PasswordInput/PasswordInput.tsx:135 setInput is a useCallback with empty deps that reads the caller's ref only when the input first attaches, so a caller ref that changes after mount is never set and the old one keeps pointing at the input. fixed 37b1905
2 Important src/components/PasswordInput/PasswordInput.tsx:141 Removing the value attribute also clears the input's default value, so a native form reset blanks the field on screen without a change event, leaving React state and the submit handler with the old password. fixed 37b1905

Security review: not re-run (round 2)

Posted inline: 2 · already inline from this round: 0 · table only (outside the diff): 0 · repeats of an earlier round dropped: 0 · Nits over the cap of 3 dropped: 0 · not posted (no file:line, or style-only): 0

Round 1 — 3182bc6

# Tag File:line Finding Outcome
1 Important src/components/PasswordInput/PasswordInput.css:9 The new .uic-password-input root is the flex item a parent row sizes, but it has no min-width: 0, which brings back the overflow Astryx fixed by putting minWidth: 0 on the Field root. fixed 63b8e5b
2 Nit src/components/PasswordInput/PasswordInput.css:24 The toggle is always IconButton size="sm" (28px) with geometry fixed to --size-element-sm, whatever the field's size or SizeContext is. fixed 63b8e5b
3 Important src/components/PasswordInput/PasswordInput.css:32 Form.Item's hasFeedback glyph sits absolutely at inset-inline-end: var(--spacing-3) (12px from the end), which falls inside the toggle (4px to 32px from the end), so the success or error glyph is drawn on top of the eye icon. fixed 63b8e5b
4 Important src/components/PasswordInput/PasswordInput.tsx:98 wasDisabled starts at the first render's isDisabled, so a field that mounts disabled never gets re-masked, and with defaultIsRevealed it shows the password once it is enabled. fixed 63b8e5b
5 Important src/components/PasswordInput/PasswordInput.tsx:101 Re-masking on disable changes the reveal state without calling onRevealedChange(false), so a listener's or a controlled parent's state stays true and a controlled field shows the password again when the form is re-enabled. fixed 63b8e5b
6 Important src/components/PasswordInput/PasswordInput.tsx:120 React keeps the input's value attribute equal to the controlled value, so the typed password sits in the DOM as value="..." on every keystroke; antd's Input.Password removes that attribute and this component does not. fixed 63b8e5b
7 Important src/components/PasswordInput/PasswordInput.tsx:122 The field stays type="text" when the form is submitted or the page comes back from bfcache; there is no hide-on-submit or pageshow reset like GOV.UK's password input has. fixed 63b8e5b
8 Important src/components/PasswordInput/PasswordInput.tsx:126 Inside Astryx InputGroup or a horizontal-labels FormLayout, Astryx renders no Field box, so the always-passed containerClassName triggers a dev warning on every use, the layout classes are dropped, and the extra root div breaks the group or grid structure; an InputGroup isDisabled also does not mask the field, because isDisabled reads only field.isDisabled. The root cause is the overlay itself (TextInput has no end slot), which also drives the min-width, feedback-icon and size findings. intentional — e0684a9 (rest fixed 63b8e5b; horizontal-labels FormLayout documented as unsupported)
9 Nit src/components/PasswordInput/PasswordInput.tsx:149 The lucide icons are sized size="1em", which follows the button's label font-size and ignores the icon size the Button provides through IconDefaultSizeProvider and iconBoxSizeStyles; Astryx <Icon icon={Eye}/>, as SelectionLabel and PageHeader use, would follow it. not-worth
10 Nit src/components/PasswordInput/PasswordInput.tsx:158 Only keydown propagation is stopped, so keypress and keyup for Enter on the toggle still reach ancestor handlers; it also blocks document-level keydown listeners, but not native listeners on the form. fixed 63b8e5b

Security review: 1 finding (posted above as Important)

Posted inline: 10 · already inline from this round: 0 · table only (outside the diff): 0 · repeats of an earlier round dropped: 0 · Nits over the cap of 3 dropped: 0 · not posted (no file:line, or style-only): 0

- Put the toggle inside the field's trailing padding, positioned in a root
  that takes the field's width, instead of a flex row with a negative
  margin. The control keeps Astryx's border, focus and status styling, so
  there is no seam, no containerClassName, and it works in an InputGroup.
- Size the toggle to fit inside a small field's border.
- Move Form.Item's hasFeedback icon to the toggle's start and reserve its
  room.
- Give the root min-width: 0 so it shrinks in a flex row.
- A field that mounts disabled starts masked.
- Stop Enter keyup and keypress on the toggle as well as keydown.
- Keep the password out of the input's value attribute.
- Mask again, and report onRevealedChange(false), when the field is
  disabled, when its form submits and on a back/forward-cache restore.
github-actions Bot added a commit that referenced this pull request Nov 23, 2026

@agatha197 agatha197 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ready-gate agent review — 2 findings — 2 Important, 0 Nit, 0 Pre-existing. The summary comment on this PR lists every finding and its outcome.

github-actions Bot added a commit that referenced this pull request Nov 23, 2026
github-actions Bot added a commit that referenced this pull request Nov 23, 2026
@agatha197
agatha197 marked this pull request as ready for review November 23, 2026 13:37
agatha197 pushed a commit to lablup/backend.ai-webui that referenced this pull request Nov 23, 2026
… preview

Takes the ready-gate fixes of #173: the toggle sits in the control's
trailing padding, the password stays out of the value attribute, and
the field re-masks on submit, on bfcache restore and when disabled.
BAIPasswordInput's visual baselines move with the new layout.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
github-actions Bot added a commit that referenced this pull request Nov 24, 2026
@agatha197
agatha197 merged commit 1eb7ebf into main Nov 24, 2026
14 checks passed
agatha197 pushed a commit to lablup/backend.ai-webui that referenced this pull request Nov 24, 2026
…n#173

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

This branch was successfully deployed

1 active deployment
release — eabfc7e7 Deployed Nov 24, 2026 by agatha197 via npmjs #200
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant