Toolforge Docs
DocsIO PrimitivestextInput

textInput

Prompts the user for a text input. Supports validation, secure inputs (passwords), and different input modes.

text-input

Usage

const name = await io.textInput({
  label: 'Enter your name',
  description: 'This will be used for personalization',
})

Props

PropDescriptionTypeRequiredDefault
labelThe label for the text inputstringYes
descriptionThe description for the text inputstringNoundefined
optionalWhether the text input is optional. When true, return type is string | undefinedbooleanNofalse
secureWhether the text input is secure (used for passwords, etc.)booleanNofalse
inputTypeThe type of validation for the text input'email' | 'url'Noundefined
modeThe mode of the text input'input' | 'textarea'No'input'
minThe minimum number of characters requirednumberNoundefined
maxThe maximum number of characters allowednumberNoundefined
maxRetryAttemptsMaximum retry attempts for invalid inputnumberNo5
validationSchemaCustom validation schema. If not provided, defaults are inferred from other propsz.ZodString | z.ZodOptional<z.ZodString>Noundefined
defaultValueThe default value for the text inputstringNoundefined

Returns

Returns a Promise<string> or Promise<string | undefined> if optional: true.

Examples

Email input

Email input

const email = await io.textInput({
  label: 'Email Address',
  inputType: 'email',
  validationSchema: z.string().email('Please enter a valid email'),
})

Secure password input

Secure password input

const password = await io.textInput({
  label: 'Password',
  secure: true,
  min: 8,
  max: 100,
})

Textarea mode

Textarea mode

const bio = await io.textInput({
  label: 'Biography',
  mode: 'textarea',
  max: 500,
  description: 'Maximum 500 characters',
})

Optional input with custom validation

Optional input with custom validation

const username = await io.textInput({
  label: 'Username (optional)',
  optional: true,
  validationSchema: z
    .string()
    .min(3, 'Username must be at least 3 characters')
    .regex(
      /^[a-z0-9_]+$/,
      'Username can only contain lowercase letters, numbers, and underscores',
    )
    .optional(),
  maxRetryAttempts: 3,
})

// TypeScript knows username can be undefined
if (username) {
  console.log(`Username: ${username}`)
}

On this page