Inquirer.js icon indicating copy to clipboard operation
Inquirer.js copied to clipboard

[feature] automatically set prompt to edit default without pressing tab

Open Da-nie-elT opened this issue 7 months ago • 1 comments

When setting a default on an input prompt you can "press tab to inline the value for edits". I would like this behavior to happen automatically without having to press tab.

This could be done with an extra option called inlineDefault: boolean or similar.

link to original tab feature request: #1215

Da-nie-elT avatar May 02 '25 13:05 Da-nie-elT

Interface wise, I think it'd be cleaner to have a different prop name like value or prefill or something like this. And make default or this key exclusive in the TS types.

SBoudrias avatar May 08 '25 21:05 SBoudrias

Hey @SBoudrias long time user, first time contributor. I'd like to tackle this one.

Is there a preconceived way of implementing this feature already? Are you aware of potentially any traps or pitfalls around this area?

Proposed Implementation

// BWC behaviour prefill 'tab' (or omitted will allow the user to prefill the text with the default value for editing'
input({
  message: "Choose a username",
  default: 'SBoudrias',
  prefill: 'tab' // Or omit (under the hood 'tab' is the default)
})

// New behaviour, when prefill is set to 'always' it will populate the input field with the default value so the user can edit and submit
input({
  message: "Choose a username",
  default: 'SBoudrias',
  prefill: 'always' // will always set the initial value of the input with the default value.
})

// The prefill prop does nothing when default is not set
input({
  message: "Choose a username",
  prefill: 'always' // Does nothing
})

input({
  message: "Choose a username",
  prefill: 'tab' // Does nothing
})

I'll make sure to update the documentation to explain this behaviour.

Please let me know if this aligns and I'll whip up a PR.

wannabewayno avatar Jun 23 '25 00:06 wannabewayno

Hey @wannabewayno contribution welcomed! And I like the approach.

Let's just rename 'always' to 'editable' or 'inline' I think? I don't feel always properly communicate the behavior.

SBoudrias avatar Jun 23 '25 19:06 SBoudrias

I like the 'editable' suggestion, much clearer. Thanks!

wannabewayno avatar Jun 24 '25 00:06 wannabewayno