Multi-Select
Allowing the Select component to select multiple values by passing an array to the defaultValue
prop on the SelectProvider
component.
Favorite food
123456789101112131415161718192021222324252627282930313233343536373839404142
import {} from "@ariakit/react";import { useState } from "react";import list from "./list.ts";import "./style.css";function renderValue(value: string[]) {if (value.length === 0) return "No food selected";if (value.length === 1) return value[0];return `${value.length} food selected`;}export default function Example() {const [value, setValue] = useState(["Apple", "Cake"]);return (<div className="wrapper">{renderValue(value)}{list.map((value) => ({value}))}</div>);}import {} from "@ariakit/react";import { useState } from "react";import list from "./list.ts";import "./style.css";function renderValue(value: string[]) {if (value.length === 0) return "No food selected";if (value.length === 1) return value[0];return `${value.length} food selected`;}export default function Example() {const [value, setValue] = useState(["Apple", "Cake"]);return (<div className="wrapper">{renderValue(value)}{list.map((value) => ({value}))}</div>);}