Usage
MultiSelect
Simple
import React, { useState } from "react";
import { MultiSelect, Options } from "react-multis";
const App = () => {
const options = [
{ value: "chocolate", label: "Chocolate" },
{ value: "strawberry", label: "Strawberry" },
{ value: "vanilla", label: "Vanilla" },
{ value: "strawberryss", label: "Strawberry" },
];
const handleSelect = (selectedValue: Options[]) => {
console.log(selectedValue);
};
return (
<MultiSelect options={options} onChange={handleSelect} />
);
};
export default App;
Search
import React, { useState } from "react";
import { MultiSelect, Options } from "react-multis";
const App = () => {
const options = [
{ value: "chocolate", label: "Chocolate" },
{ value: "strawberry", label: "Strawberry" },
{ value: "vanilla", label: "Vanilla" },
{ value: "strawberryss", label: "Strawberry" },
];
const handleSelect = (selectedValue: Options[]) => {
console.log(selectedValue);
};
return (
<MultiSelect
options={options}
onChange={handleSelect}
isSearchable
/>
);
};
export default App;
Select To Show Checked
import React, { useState } from "react";
import { MultiSelect, Options } from "react-multis";
const App = () => {
const options = [
{ value: "chocolate", label: "Chocolate" },
{ value: "strawberry", label: "Strawberry" },
{ value: "vanilla", label: "Vanilla" },
{ value: "strawberryss", label: "Strawberry" },
];
const handleSelect = (selectedValue: Options[]) => {
console.log(selectedValue);
};
return (
<MultiSelect
options={options}
onChange={handleSelect}
checked={false}
/>
);
};
export default App;
Customize Width
import React, { useState } from "react";
import { MultiSelect, Options } from "react-multis";
const App = () => {
const options = [
{ value: "chocolate", label: "Chocolate" },
{ value: "strawberry", label: "Strawberry" },
{ value: "vanilla", label: "Vanilla" },
{ value: "strawberryss", label: "Strawberry" },
];
const handleSelect = (selectedValue: Options[]) => {
console.log(selectedValue);
};
return (
<MultiSelect
options={options}
onChange={handleSelect}
isSearchable
/>
);
};
export default App;
Customize Height
import React, { useState } from "react";
import { MultiSelect, Options } from "react-multis";
const App = () => {
const options = [
{ value: "chocolate", label: "Chocolate" },
{ value: "strawberry", label: "Strawberry" },
{ value: "vanilla", label: "Vanilla" },
{ value: "strawberryss", label: "Strawberry" },
];
const handleSelect = (selectedValue: Options[]) => {
console.log(selectedValue);
};
return (
<MultiSelect
options={options}
onChange={handleSelect}
maxHeight={500}
/>
);
};
export default App;
Creatable
import React, { useState } from "react";
import { MultiSelect, Options } from "react-multis";
const App = () => {
const options = [
{ value: "chocolate", label: "Chocolate" },
{ value: "strawberry", label: "Strawberry" },
{ value: "vanilla", label: "Vanilla" },
{ value: "strawberryss", label: "Strawberry" },
];
const handleSelect = (selectedValue: Options[]) => {
console.log(selectedValue);
};
return (
<MultiSelect
options={options}
onChange={handleSelect}
isSearchable
creatable
/>
);
};
export default App;
Disabled
import React, { useState } from "react";
import { MultiSelect, Options } from "react-multis";
const App = () => {
const options = [
{ value: "chocolate", label: "Chocolate" },
{ value: "strawberry", label: "Strawberry" },
{ value: "vanilla", label: "Vanilla" },
{ value: "strawberryss", label: "Strawberry" },
];
const handleSelect = (selectedValue: Options[]) => {
console.log(selectedValue);
};
return (
<MultiSelect
options={options}
onChange={handleSelect}
disabled
/>
);
};
export default App;
Size
import React, { useState } from "react";
import { MultiSelect, Options } from "react-multis";
const App = () => {
const options = [
{ value: "chocolate", label: "Chocolate" },
{ value: "strawberry", label: "Strawberry" },
{ value: "vanilla", label: "Vanilla" },
{ value: "strawberryss", label: "Strawberry" },
];
const handleSelect = (selectedValue: Options[]) => {
console.log(selectedValue);
};
return (
<MultiSelect
options={options}
onChange={handleSelect}
size={"sm"}
/>
);
};
export default App;
Default
import React, { useState } from "react";
import { MultiSelect, Options } from "react-multis";
const App = () => {
const options = [
{ value: "chocolate", label: "Chocolate" },
{ value: "strawberry", label: "Strawberry" },
{ value: "vanilla", label: "Vanilla" },
{ value: "strawberryss", label: "Strawberry" },
];
const handleSelect = (selectedValue: Options[]) => {
console.log(selectedValue);
};
return (
<MultiSelect
options={options}
onChange={handleSelect}
isSearchable
creatable
/>
);
};
export default App;
Maximum Acceptable Items Limit
import React, { useState } from "react";
import { MultiSelect, Options } from "react-multis";
const App = () => {
const options = [
{ value: "chocolate", label: "Chocolate" },
{ value: "strawberry", label: "Strawberry" },
{ value: "vanilla", label: "Vanilla" },
{ value: "strawberryss", label: "Strawberry" },
];
const handleSelect = (selectedValue: Options[]) => {
console.log(selectedValue);
};
return (
<MultiSelect
options={options}
onChange={handleSelect}
maxAcceptItem={5}
/>
);
};
export default App;
PlaceholderText
import React, { useState } from "react";
import { MultiSelect, Options } from "react-multis";
const App = () => {
const options = [
{ value: "chocolate", label: "Chocolate" },
{ value: "strawberry", label: "Strawberry" },
{ value: "vanilla", label: "Vanilla" },
{ value: "strawberryss", label: "Strawberry" },
];
const handleSelect = (selectedValue: Options[]) => {
console.log(selectedValue);
};
return (
<MultiSelect
options={options}
onChange={handleSelect}
placeholderText={"Select Item..."}
/>
);
};
export default App;
Empty State
import React, { useState } from "react";
import { MultiSelect, Options } from "react-multis";
const App = () => {
const options = [
{ value: "chocolate", label: "Chocolate" },
{ value: "strawberry", label: "Strawberry" },
{ value: "vanilla", label: "Vanilla" },
{ value: "strawberryss", label: "Strawberry" },
];
const handleSelect = (selectedValue: Options[]) => {
console.log(selectedValue);
};
return (
<MultiSelect
options={options}
onChange={handleSelect}
emptyState={"Item Not Found"}
/>
);
};
export default App;
Maximum Item To Show
import React, { useState } from "react";
import { MultiSelect, Options } from "react-multis";
const App = () => {
const options = [
{ value: "chocolate", label: "Chocolate" },
{ value: "strawberry", label: "Strawberry" },
{ value: "vanilla", label: "Vanilla" },
{ value: "strawberryss", label: "Strawberry" },
];
const handleSelect = (selectedValue: Options[]) => {
console.log(selectedValue);
};
return (
<MultiSelect
options={options}
onChange={handleSelect}
maxLengthShow={6}
/>
);
};
export default App;
Hide Header
import React, { useState } from "react";
import { MultiSelect, Options } from "react-multis";
const App = () => {
const options = [
{ value: "chocolate", label: "Chocolate" },
{ value: "strawberry", label: "Strawberry" },
{ value: "vanilla", label: "Vanilla" },
{ value: "strawberryss", label: "Strawberry" },
];
const handleSelect = (selectedValue: Options[]) => {
console.log(selectedValue);
};
return (
<MultiSelect
options={options}
onChange={handleSelect}
hideHeader
/>
);
};
export default App;