Skip to content

[Bug] text validate function for text when value is empty with default value #397

@pedrofcarvalho

Description

@pedrofcarvalho

Environment

  • OS: macOS
  • Node Version: 22.5.1
  • Package: @clack/promts
  • Package Version: 0.11.0

Describe the bug
When calling the text's validate function without user input but with a default value defined, it should use the default value instead of relying solely on user input.

To Reproduce

Steps to reproduce the behavior:

  1. Open repro link
  2. Run node index.js
  3. Don't type anything, just press [Enter]
  4. See behavior described on terminal

Expected behavior
Clear use case example:
Image

CLI dev creates a text step for user to enter a path as input. There's some predefined value that CLI dev established to be the default use case for most users, but still allowing for that value to be changed.
Currently, the user would have to type/copy that entire path, causing a terrible user experience.

Fix Recommendation (starting a convo)
I see 2 possible ways to fix this:

  1. Keep validate as is and add a check to the value on core/prompts/text - link to draft PR
  2. Add a second optional argument, which would be the default value to validate. That way, Devs would have another quick option when using the validate function, without adding extra checks to the core library.

My goal with this section is to start a conversation and introduce my ideas about this issue, not a way for me to impose how I think things should be.
This would be my first contribution, so I'm pretty new here. Let me know what you think and hopefully let's get this fixed!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Needs triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions