import { ComboBox, ComboBoxItem } from "@/shim-ui/combo-box";
export default () => (
<ComboBox label="Ice cream" placeholder="Pick a flavor">
<ComboBoxItem>Chocolate</ComboBoxItem>
<ComboBoxItem>Mint</ComboBoxItem>
<ComboBoxItem>Strawberry</ComboBoxItem>
<ComboBoxItem>Vanilla</ComboBoxItem>
</ComboBox>
);Install
Use the CLI or copy the source code manually.
Command
Source code
pnpm dlx @kkga/shim add combo-boximport { ComboBox, ComboBoxItem } from "@/shim-ui/combo-box";
export default () => (
<>
<ComboBox label="Size 1" placeholder="Pick a framework" size={1}>
<ComboBoxItem>React</ComboBoxItem>
<ComboBoxItem>Svelte</ComboBoxItem>
</ComboBox>
<ComboBox label="Size 2" placeholder="Pick a framework" size={2}>
<ComboBoxItem>React</ComboBoxItem>
<ComboBoxItem>Svelte</ComboBoxItem>
</ComboBox>
<ComboBox label="Size 3" placeholder="Pick a framework" size={3}>
<ComboBoxItem>React</ComboBoxItem>
<ComboBoxItem>Svelte</ComboBoxItem>
</ComboBox>
<ComboBox label="Size 4" placeholder="Pick a framework" size={4}>
<ComboBoxItem>React</ComboBoxItem>
<ComboBoxItem>Svelte</ComboBoxItem>
</ComboBox>
</>
);Content
ComboBox follows the Collections API and supports both static and dynamic items.
Pass an items prop and a render function as children to render dynamic collections. The render function receives each item from items and should return a React element.
Selected topic id:
"use client";
import { useState } from "react";
import type { Key } from "react-aria-components";
import { ComboBox, ComboBoxItem } from "@/shim-ui/combo-box";
export default () => {
let options = [
{ id: 1, name: "Aerospace" },
{ id: 2, name: "Mechanical" },
{ id: 3, name: "Civil" },
{ id: 4, name: "Biomedical" },
{ id: 5, name: "Nuclear" },
{ id: 6, name: "Industrial" },
{ id: 7, name: "Chemical" },
{ id: 8, name: "Agricultural" },
{ id: 9, name: "Electrical" },
];
let [majorId, setMajorId] = useState<Key | null>(null);
return (
<>
<ComboBox
aria-label="Select a major"
defaultItems={options}
onSelectionChange={setMajorId}
>
{(item) => <ComboBoxItem>{item.name}</ComboBoxItem>}
</ComboBox>
<p>Selected topic id: {majorId}</p>
</>
);
};