Skip to content

Conversation

@kajoseph
Copy link
Contributor

@kajoseph kajoseph commented Aug 5, 2025

This PR adds a clearOnError option to the password prompt to enforce typing the whole password again on an error. This is particularly useful when mask: '' (i.e. a hidden input) is given.

e.g. Consider this case

const pw = await prompt.password({
  message: 'Please enter your password:',
  mask: '',
  validate: (val) => val === 'test123' ? undefined : 'Password must be "test123"'
});

If the user enters "password" and hits return, an (expected) error Password must be "test123" will appear, like so:
image
The user then enters "test123" and hits return. They will get the same error because the value is actually "passwordtest123" which is not apparent with a hidden input.

This PR adds a clearOnError boolean option to have the input clear out after an error to avoid the confusion above.

@changeset-bot
Copy link

changeset-bot bot commented Aug 5, 2025

🦋 Changeset detected

Latest commit: 040266b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@clack/prompts Minor
@clack/core Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@43081j
Copy link
Collaborator

43081j commented Aug 7, 2025

im thinking it may make more sense to call it clear rather than reset, since it does empty the input.

if a prompt has a default value, i'd expect reset to reset back to that. while i'd expect clear to empty the input

@kajoseph kajoseph changed the title feat: add input reset to password prompt feat: add param to clear input after password prompt error Aug 7, 2025
Copy link
Member

@dreyfus92 dreyfus92 left a comment

Choose a reason for hiding this comment

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

Awesome work @kajoseph, thank you for taking the time on working on this. I left a small suggestion to make the changeset a bit clearer and concise.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Aug 10, 2025

@example/basic@example/changesets

npm i https://pkg.pr.new/bombshell-dev/clack/@clack/core@364
npm i https://pkg.pr.new/bombshell-dev/clack/@clack/prompts@364

commit: 040266b

@43081j 43081j merged commit 1604f97 into bombshell-dev:main Aug 11, 2025
7 checks passed
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.

3 participants