Skip to content

feat: add param to clear input after password prompt error #364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

kajoseph
Copy link

@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.

Copy link

changeset-bot bot commented Aug 5, 2025

🦋 Changeset detected

Latest commit: 8671c5f

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.

"@clack/core": minor
---

Add input reset to password prompt
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Add input reset to password prompt
Add `clearOnError` option to password prompt to automatically clear input when validation fails

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