clack
clack copied to clipboard
[Bug] Adding the placeholder attribute to the text method will affect the result of the validate method
Environment
- OS: [macOS]
- Node Version: [v20.11.0]
- Package: [
@clack/prompts] - Package Version: [v0.10.1]
Describe the bug
[Bug] validate method of text take the placeholder #29
what do you expect the behaviour to be?
if you <tab> or <return> on the placeholder, it will set the value to the placeholder.
we could alternatively set the value to the placeholder after running validate, but that feels odd too. since it means value will be undefined even though we're about to set it to the placeholder.
// index.js
async function main() {
const name = await text({
message: "What is your name?",
// placeholder: "any",
initialValue: "42",
validate(value) {
if (!value) return `Value is required!`;
},
});
}
main()
start node index.js
When I deleted '42', The validate method is working properly, and preventing me from using enter to proceed to the next step
But if I add a placeholder, even if it's an empty string, The validate method is not working properly
// index.js
async function main() {
const name = await text({
message: "What is your name?",
placeholder: "",
initialValue: "42",
validate(value) {
if (!value) return `Value is required!`;
},
});
}
main()
The expected behavior of the placeholder will not affect the validate method
that is because submitting when there is a placeholder will set the value to the placeholder
if you press <tab> or <return>, you're saying "use the placeholder as my value"
so naturally the value isn't empty, because you chose the placeholder as your value.
what did you expect the placeholder to do? behave more like an <input> placeholder? (i.e. not affect the value)