Skip to main content

Overview

The ChipInput component provides an input field that allows users to enter multiple values, which are then displayed as chips. It supports adding values on pressing Enter or clicking outside the input, and removing or updating values by interacting with the chips.

Import

import ChipInput from "@components/chip-input/ChipInput";

Usage Example

import React, { useState } from "react";
import ChipInput from "./ChipInput";

const ChipInputDemo = () => {
const [values, setValues] = useState(["Initial Chip"]);

const handleValuesChange = (updatedValues) => {
console.log("Updated Values:", updatedValues);
setValues(updatedValues);
};

return (
<ChipInput
value={values}
onChange={handleValuesChange}
name="my-chip-input"
separateInput={false} // Set to true to render chips over the input
variant="filled" // or 'outlined'
accent="teal" // or other color accents
style={{ width: "100%" }} // Optional style
/>
);
};

export default ChipInputDemo;

Result

Props

Prop NameTypeDescription
valueArray<string>An array of strings representing the initial values to be displayed as chips.
onChange(updatedValues: Array<string>) => voidA callback function triggered when the list of chip values changes (a chip is added or removed). It receives the updated array of values.
namestringThe name attribute for the underlying input element.
separateInputbooleanIf true, renders the chips below the input field; otherwise, renders them within the input field area.
variantstringThe visual variant of the chips (e.g., "filled", "outlined"). Defaults to "filled".
accentstringThe color accent of the chips (e.g., "teal"). Defaults to "teal".