Components · Controls

Text field

A free-text input, reported once the reader pauses typing.

Open in playground

Preview

Search

Usage

tsx
import { useState } from 'react';
import { ChartsProvider, TextField } from 'em-kit';

export const Example = () => {
  const [text, setText] = useState('');
  return (
    <ChartsProvider>
      <div style={{ width: 320 }}>
        <TextField
          title="Search"
          placeholder="Type to search"
          value={text}
          onChange={setText}
        />
      </div>
    </ChartsProvider>
  );
};

Install with npm install em-kit. Needs <ChartsProvider> once, and your own state for its value: Quick start.

Examples

Starting text

The field opens with text already in it, such as a search carried over from another page. value is read once, when the field mounts.

tsxDiffers from Usage
Show full code (18 lines)
import { useState } from 'react';
import { ChartsProvider, TextField } from 'em-kit';

export const Example = () => {
  const [text, setText] = useState('Enterprise');
  return (
    <ChartsProvider>
      <div style={{ width: 320 }}>
        <TextField
          title="Search"
          placeholder="Type to search"
          value={text}
          onChange={setText}
        />
      </div>
    </ChartsProvider>
  );
};
const [text, setText] = useState('Enterprise');

<TextField
  title="Search"
  placeholder="Type to search"
  value={text}
  onChange={setText}
/>

Props

Keyboard and screen readers: Accessibility.

PropTypeDefaultDescription
valuestringThe text the field starts with. The field then keeps what is typed and reports it through onChange.
placeholderstringText shown while nothing is chosen. Translates like title.
componentNamestringA name for this component, included in the interaction events it dispatches on the DOM, for your analytics.
trackingIdstringAn id included in the same events, to tell two instances apart.
onChange(value: string) => voidCalled with the text once the reader pauses typing, and once with the starting text when the field mounts.
titlestringThe title over the field. A "key|fallback" string is looked up in your translations.
descriptionstringSmaller text under the title. Translates like title.
tooltipstringText for an info icon beside the title.

A blank default means the prop is unset unless you pass it.

Field options

TextField reads only the common options in a field’s inputs.