Skip to content

Textbox

Single or multi-line text input component.

Import

typescript
import gr from 'egenerui'

Usage

Basic Textbox

typescript
const textbox = gr.Textbox({
  label: "Name",
  placeholder: "Enter your name"
})

Multi-line Textbox

typescript
const message = gr.Textbox({
  label: "Message",
  lines: 4,
  maxLines: 10,
  placeholder: "Write your message here..."
})

Password Input

typescript
const password = gr.Textbox({
  label: "Password",
  type: "password",
  placeholder: "Enter your password"
})

Props

NameTypeDefaultDescription
labelstring-Label text
valuestring''Initial value
placeholderstring-Placeholder text
linesnumber1Number of lines (multi-line when > 1)
maxLinesnumber-Maximum number of lines
type'text' | 'password' | 'email' | 'number''text'Input type
showLabelbooleantrueShow label
interactivebooleantrueEnable interaction
autofocusbooleanfalseAuto focus on mount
elemIdstring-Custom element ID
elemClassesstring | string[]-Custom CSS classes

Methods

focus()

Focus the input element.

typescript
textbox.focus()

select()

Select all text in the input.

typescript
textbox.select()

clear()

Clear the input value.

typescript
textbox.clear()

onInput()

Bind input event handler.

typescript
textbox.onInput((value) => {
  console.log('Input changed:', value)
})

Events

change

Emitted when the value changes.

typescript
textbox.change((value) => {
  console.log('Value changed:', value)
})

Examples

Form with Validation

typescript
const email = gr.Textbox({
  label: "Email",
  type: "email",
  placeholder: "your.email@example.com"
})

const submit = gr.Button("Submit").primary()

submit.click(() => {
  const value = email.value
  if (!value.includes('@')) {
    alert('Please enter a valid email')
    return
  }
  console.log('Valid email:', value)
})

Character Counter

typescript
const text = gr.Textbox({
  label: "Text",
  lines: 3,
  maxLines: 5,
  placeholder: "Type something..."
})

const counter = gr.Label({ label: "Characters" })

text.change((value) => {
  counter.value = `${value.length} / 500 characters`
})

Live Demo

You can try the Textbox component in the Basic Form example.

基于 MIT 许可发布