Text field
A free-text input, reported once the reader pauses typing.
Preview
Search
Usage
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.
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.
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | The text the field starts with. The field then keeps what is typed and reports it through onChange. | |
placeholder | string | Text shown while nothing is chosen. Translates like title. | |
componentName | string | A name for this component, included in the interaction events it dispatches on the DOM, for your analytics. | |
trackingId | string | An id included in the same events, to tell two instances apart. | |
onChange | ( | Called with the text once the reader pauses typing, and once with the starting text when the field mounts. | |
title | string | The title over the field. A "key|fallback" string is looked up in your translations. | |
description | string | Smaller text under the title. Translates like title. | |
tooltip | string | Text 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.