1.1.0 • Published 4 years ago

material-ui-chip-input v1.1.0

Weekly downloads
46,934
License
MIT
Repository
github
Last release
4 years ago

material-ui-chip-input

Build Status Coverage Status

This project provides a chip input field for Material-UI. It is inspired by Angular Material's chip input.

Demo

If you want to try the component yourself instead of watching a gif, head over to the storybook for a live demo!

Installation

npm i --save material-ui-chip-input@next

Usage

The component supports either controlled or uncontrolled input mode. If you use the controlled mode (by setting the value attribute), the onChange callback won't be called.

import ChipInput from 'material-ui-chip-input'

// uncontrolled input
<ChipInput
  defaultValue={['foo', 'bar']}
  onChange={(chips) => handleChange(chips)}
/>

// controlled input
<ChipInput
  value={yourChips}
  onAdd={(chip) => handleAddChip(chip)}
  onDelete={(chip, index) => handleDeleteChip(chip, index)}
/>

Properties

NameTypeDefaultDescription
allowDuplicatesboolfalseAllows duplicate chips if set to true.
chipRendererfunctionA function of the type ({ value, text, chip, isFocused, isDisabled, handleClick, handleDelete, className }, key) => node that returns a chip based on the given properties. This can be used to customize chip styles. Each item in the dataSource array will be passed to chipRenderer as arguments chip, value and text. If dataSource is an array of objects and dataSourceConfig is present, then value and text will instead correspond to the object values defined in dataSourceConfig. If dataSourceConfig is not set and dataSource is an array of objects, then a custom chipRenderer must be set. chip is always the raw value from dataSource, either an object or a string.
classesobjectExtends the styles applied to this component.
clearOnBlurbooltrueIf true, clears the input value after the component loses focus.
dataSourcearrayData source for auto complete. This should be an array of strings or objects.
dataSourceConfigobjectConfig for objects list dataSource, e.g. { text: 'text', value: 'value' }. If not specified, the dataSource must be a flat array of strings or a custom chipRenderer must be set to handle the objects.
defaultValuestring[]The chips to display by default (for uncontrolled mode).
disabledboolfalseDisables the chip input if set to true.
helperTextnodeThe helper text to display.
inputReffunctionUse that property to pass a ref callback to the native input component.
fullWidthboolfalseIf true, the chip input will fill the available width.
fullWidthInputboolfalseIf true, the input field will always be below the chips and fill the available space. By default, it will try to be beside the chips.
labelnodeThe content of the floating label.
newChipKeyCodesnumber[][13] (enter key)The key codes used to determine when to create a new chip.
onBeforeAddfunctionCallback function that is called with the chip to be added and should return true to add the chip or false to prevent the chip from being added without clearing the text input.
onBlurfunctionCallback function that is called with event when the input loses focus, where event.target.value is the current value of the text input.
onChangefunctionCallback function that is called when the chips change (in uncontrolled mode).
onAddfunctionCallback function that is called when a new chip was added (in controlled mode).
onDeletefunctionCallback function that is called when a new chip was removed (in controlled mode).
onUpdateInputfunctionCallback function that is called when the input changes.
placeholdernodeA short placeholder that is displayed if the input has no values.
valuestring[]The chips to display (enables controlled mode if set).

Any other properties supplied will be spread to the root element. The properties of <FormControl /> are also available.

CSS API

You can customize the class names used by ChipInput with the classes property. It accepts the following keys:

  • root
  • inputRoot
  • input
  • chipContainer
  • label
  • helperText
  • chip

Have a look at this guide for more detail.

Credits

The code for the input component was adapted from Material UI's Text Field that we all know and love.

License

The files included in this repository are licensed under the MIT license.

1.1.0

4 years ago

2.0.0-beta.2

4 years ago

2.0.0-beta.1

5 years ago

1.0.0

5 years ago

1.0.0-beta.17

5 years ago

1.0.0-beta.16

5 years ago

1.0.0-beta.15

5 years ago

1.0.0-beta.14

5 years ago

1.0.0-beta.13

5 years ago

1.0.0-beta.12

5 years ago

1.0.0-beta.11

5 years ago

1.0.0-beta.10

5 years ago

1.0.0-beta.9

5 years ago

1.0.0-beta.8

6 years ago

1.0.0-beta.7

6 years ago

1.0.0-beta.6

6 years ago

1.0.0-beta.5

6 years ago

0.19.0

6 years ago

0.18.8

6 years ago

0.18.7

6 years ago

1.0.0-beta.4

6 years ago

0.18.6

6 years ago

1.0.0-beta.3

6 years ago

0.18.5

6 years ago

1.0.0-beta.2

6 years ago

0.18.4

6 years ago

1.0.0-beta.1

6 years ago

0.18.3

6 years ago

0.18.2

6 years ago

0.18.1

7 years ago

0.18.0

7 years ago

0.17.2

7 years ago

0.17.1

7 years ago

0.17.0

7 years ago

0.16.1

7 years ago

0.16.0

7 years ago

0.15.3

7 years ago

0.15.2

7 years ago

0.15.1

7 years ago

0.15.0

7 years ago

0.14.0

7 years ago

0.13.6

7 years ago

0.13.5

7 years ago

0.13.4

7 years ago

0.13.3

7 years ago

0.13.2

7 years ago

0.13.1

7 years ago

0.13.0

7 years ago

0.12.2

7 years ago

0.12.1

7 years ago

0.12.0

7 years ago

0.11.4

7 years ago

0.11.3

7 years ago

0.11.2

7 years ago

0.11.1

7 years ago

0.11.0

7 years ago

0.10.0

7 years ago

0.9.1

7 years ago

0.9.0

7 years ago

0.8.0

8 years ago

0.7.0

8 years ago

0.5.1

8 years ago

0.5.0

8 years ago

0.4.1

8 years ago

0.4.0

8 years ago

0.3.3

8 years ago

0.3.2

8 years ago

0.3.1

8 years ago

0.3.0

8 years ago

0.2.2

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.0

8 years ago