UNPKG

3.1 kBMarkdownView Raw
1@# Tag input
2
3Tag inputs render [`Tag`](#core/components/tag)s inside an input, followed by an
4actual text input. The container is merely styled to look like a Blueprint
5input; the actual editable element appears after the last tag. Clicking anywhere
6on the container will focus the text input for seamless interaction.
7
8@reactExample TagInputExample
9
10<div class="@ns-callout @ns-intent-success @ns-icon-info-sign">
11 <h4 class="@ns-heading">Looking for a dropdown menu?</h4>
12
13[`MultiSelect` in the **@blueprintjs/select** package](#select/multi-select)
14composes this component with a dropdown menu of suggestions.
15
16</div>
17
18@## Props
19
20**`TagInput` must be controlled,** meaning the `values` prop is required and
21event handlers are strongly suggested. Typing in the input and pressing
22<kbd>enter</kbd> will **add new items** by invoking callbacks. If `addOnBlur` is
23set to true, clicking out of the component will also trigger the callback to add
24new items. A `separator` prop is supported to allow multiple items to be added
25at once; the default splits on commas and newlines.
26
27**Tags can be removed** by clicking their <span class="@ns-icon-standard @ns-icon-cross"></span>
28buttons, or by pressing either <kbd>backspace</kbd> or <kbd>delete</kbd> repeatedly.
29Pressing <kbd>delete</kbd> mimics the behavior of deleting in a text editor, where trying to delete at the end of the line will do nothing.
30Arrow keys can also be used to focus on a particular tag before removing it. The
31cursor must be at the beginning of the text input for these interactions.
32
33**`Tag` appearance can be customized** with `tagProps`: supply an object to
34apply the same props to every tag, or supply a callback to apply dynamic props
35per tag. Tag `values` must be an array of strings so you may need a
36transformation step between your state and these props.
37
38`TagInput` provides granular `onAdd` and `onRemove` **event props**, which are
39passed the added or removed items in response to the user interactions above. It
40also provides `onChange`, which combines both events and is passed the updated
41`values` array, with new items appended to the end and removed items filtered
42away.
43
44The `<input>` element can be controlled directly via the `inputValue` and
45`onInputChange` props. Additional properties (such as custom event handlers) can
46be applied to the input via `inputProps`.
47
48<div class="@ns-callout @ns-intent-primary @ns-icon-info-sign">
49 <h4 class="@ns-heading">Handling long words</h4>
50
51Set an explicit `width` on the container element to cause long tags to wrap onto multiple lines.
52Either supply a specific pixel value, or use `<TagInput className={Classes.FILL}>`
53to fill its container's width (try this in the example above).
54
55</div>
56
57<div class="@ns-callout @ns-intent-primary @ns-icon-info-sign">
58 <h4 class="@ns-heading">Disabling a tag input</h4>
59
60Disabling this component requires setting the `disabled` prop to `true`
61and separately disabling the component's `rightElement` as appropriate
62(because `TagInput` accepts any `JSX.Element` as its `rightElement`).
63
64</div>
65
66@interface ITagInputProps