Skip to content

Conversation

@43081j
Copy link
Collaborator

@43081j 43081j commented May 28, 2025

Fixes #330

Basically, this introduces a new userInput field and event to the core.

The difference is:

  • userInput tracks what the user has typed in (if track: true)
  • nothing changes value in the core anymore

This means it is the responsibility of each prompt to decide what to do with value. They can then call this._setValue(value) to set the value and trigger the value event.

An example - text prompt

The text prompt wants to set the value to what the user has typed in. So we can simply listen for userInput and set value to whatever they have typed. Or we can wait for finalize and do it.

A more complex example - auto complete

The auto complete prompt wants to take user input, but this isn't the value. The value should be the completed value.

To achieve this, we can set value only once someone selects an option.

This means the value is only ever undefined or a selected option.

Notable changes

  • Validation only occurs when you submit (press <RETURN>), it used to run against initial values too
  • Validation can receive undefined (it always could but we didn't type it as such, iirc)
  • Validation function is strongly typed (i.e. it takes value as a strong type)

@43081j 43081j requested a review from dreyfus92 May 28, 2025 09:27
@changeset-bot
Copy link

changeset-bot bot commented May 28, 2025

🦋 Changeset detected

Latest commit: 831029d

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

@pkg-pr-new
Copy link

pkg-pr-new bot commented May 28, 2025

@example/basic@example/changesets

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

commit: 831029d

@43081j 43081j mentioned this pull request May 28, 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.

i really like this refactor, you're just lacking a changeset and i'm wondering if these changes impact all the examples we've created in the examples dir

@43081j 43081j mentioned this pull request Jun 2, 2025
12 tasks
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.

Let's ship it 🫡

@43081j 43081j merged commit 7bc3301 into main Jun 3, 2025
6 checks passed
@43081j 43081j deleted the values-up-on-bricks branch June 3, 2025 16:12
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.

Prompt value should only be mutated on finalise

3 participants