TextInputWithTokens

TextInputWithTokens is an input for a value that is a list.

Page navigation navigation

React
readyNot reviewed for a11y

Use a TextInputWithTokens for lists where items can be added or removed, but not edited inline. Typically paired with autocomplete for selecting items from a list.

React examples

Default

zero (press backspace or delete to remove)one (press backspace or delete to remove)two (press backspace or delete to remove)three (press backspace or delete to remove)

Prevent wrapping

By default, tokens wrap to multiple lines. You may override this to force tokens or stay on one line in a horizontal scrolling container.

zero (press backspace or delete to remove)one (press backspace or delete to remove)two (press backspace or delete to remove)three (press backspace or delete to remove)four (press backspace or delete to remove)five (press backspace or delete to remove)six (press backspace or delete to remove)seven (press backspace or delete to remove)eight (press backspace or delete to remove)nine (press backspace or delete to remove)

With a max height

When wrapping, set a max height; exceeding rows will scroll vertically.

zero (press backspace or delete to remove)one (press backspace or delete to remove)two (press backspace or delete to remove)three (press backspace or delete to remove)four (press backspace or delete to remove)five (press backspace or delete to remove)six (press backspace or delete to remove)seven (press backspace or delete to remove)eight (press backspace or delete to remove)nine (press backspace or delete to remove)

Truncated token list

You may choose to limit the number of tokens that are visible. However, all tokens will be visible while the text input is focused.

zero (press backspace or delete to remove)one (press backspace or delete to remove)two (press backspace or delete to remove)three (press backspace or delete to remove)four (press backspace or delete to remove)+5

Props

TextInputWithTokens

NameDefaultDescription
tokens Required
TokenProps[]

The array of tokens to render

onTokenRemove Required
(tokenId: string|number) => void

The function that gets called when a token is removed

tokenComponent
Token
React.ComponentType<any>

The component used to render each token

maxHeight
React.CSSProperties['maxHeight']

The maximum height of the component. If the content in the input exceeds this height, it will scroll vertically

preventTokenWrapping
false
boolean

Whether tokens should render inline horizontally. By default, tokens wrap to new lines

size
xlarge
'small' | 'medium' | 'large' | 'xlarge'

The size of the tokens and text input

hideTokenRemoveButtons
false
boolean

Whether the remove buttons should be rendered in the tokens

validationStatus
'error' | 'success'

Style the input to match the status

visibleTokenCount
number

The number of tokens to display before truncating

See TextInput for more prop options