Skip to Content
Soundor Components
Components

TextField

A single-line input for names, labels and other free text.

Use TextField for text that is not a number: preset names, tags, search. For a number you also want to drag, use ValueField.

import { TextField } from '@soundor/components';
import { useState } from 'react';

export default function Demo() {
  const [name, setName] = useState('Warm Pad');
  return (
    <TextField
      label="Preset name"
      value={name}
      onChange={setName}
      placeholder="Untitled"
      width={200}
    />
  );
}
text-field.tsx, running in the web runtime.Source

Examples

Validation

The field does not judge the text. Pass error when it is wrong and the border turns red and the message replaces the description. Pass nothing when it is fine.

import { TextField } from '@soundor/components';
import { useState } from 'react';

export default function Demo() {
  const [name, setName] = useState('Warm/Pad');
  // Validation is yours: say what is wrong, and the field shows it.
  const error = /[\\/:*?"<>|]/.test(name)
    ? 'Names cannot contain / \\ : * ? " < > |'
    : undefined;
  return (
    <TextField
      label="File name"
      value={name}
      onChange={setName}
      description="Used when the preset is exported."
      error={error}
      width={220}
    />
  );
}
text-field-validation.tsx, running in the web runtime.Source

Sizes and states

size matches the other controls. A disabled field shows its text and can be neither focused nor edited.

import { TextField } from '@soundor/components';
import { View } from '@soundor/react';

export default function Demo() {
  return (
    <View style={{ gap: 14 }}>
      <TextField label="Empty" placeholder="Type here" width={200} />
      <TextField label="Small" size="sm" defaultValue="Compact" width={200} />
      <TextField label="Large" size="lg" defaultValue="Roomy" width={200} />
      <TextField
        label="Disabled"
        defaultValue="Factory preset"
        disabled
        width={200}
      />
    </View>
  );
}
text-field-states.tsx, running in the web runtime.Source

Usage

const [name, setName] = useState('Warm Pad');

<TextField label="Preset name" value={name} onChange={setName} />;

onChange runs after every edit. onSubmit runs on Enter, which is the place to apply or save. Leave out value and pass defaultValue to let the field keep its own text.

Keyboard and accessibility

The field is a text input, so the platform's own editing and selection shortcuts apply. Enter calls onSubmit. It is named by label, or by accessibilityLabel when you pass one. error is read as the field's hint, so the reason is announced with the field. See Keyboard and accessibility.

Props

Prop

Type

On this page