Skip to content

Commit e5c7663

Browse files
authored
fix(demo): controlled multiple of select (#5921)
1 parent dbe3d83 commit e5c7663

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed

apps/docs/src/demos/select/controlled-multiple.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
"use client";
22

3-
import type {Selection} from "@react-types/shared";
3+
import type {Key} from "@heroui/react";
44

55
import {Label, ListBox, Select} from "@heroui/react";
6-
import {useState} from "react";
6+
import React from "react";
77

88
export function ControlledMultiple() {
9-
const [selected, setSelected] = useState<Selection>(new Set(["california", "texas"]));
10-
11-
const selectedItems = Array.from(selected);
9+
const [selected, setSelected] = React.useState<Key[]>(["california", "texas"]);
1210

1311
return (
1412
<div className="space-y-4">
15-
<Select className="w-[256px]" placeholder="Select states" selectionMode="multiple">
13+
<Select
14+
className="w-[256px]"
15+
placeholder="Select states"
16+
selectionMode="multiple"
17+
value={selected}
18+
onChange={(keys) => setSelected(keys as Key[])}
19+
>
1620
<Label>States (controlled multiple)</Label>
1721
<Select.Trigger>
1822
<Select.Value />
1923
<Select.Indicator />
2024
</Select.Trigger>
2125
<Select.Popover>
22-
<ListBox
23-
selectedKeys={selected}
24-
selectionMode="multiple"
25-
onSelectionChange={(keys) => setSelected(keys as Selection)}
26-
>
26+
<ListBox selectionMode="multiple">
2727
<ListBox.Item id="california" textValue="California">
2828
California
2929
<ListBox.ItemIndicator />
@@ -52,7 +52,7 @@ export function ControlledMultiple() {
5252
</Select.Popover>
5353
</Select>
5454
<p className="text-muted text-sm">
55-
Selected: {selectedItems.length > 0 ? selectedItems.join(", ") : "None"}
55+
Selected: {selected.length > 0 ? selected.join(", ") : "None"}
5656
</p>
5757
</div>
5858
);

packages/react/src/components/select/select.stories.tsx

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type {Key} from "../rac";
2-
import type {Selection} from "@react-types/shared";
32
import type {Meta, StoryObj} from "@storybook/react";
43

54
import {Icon} from "@iconify/react";
@@ -778,24 +777,24 @@ export const Controlled: Story = {
778777

779778
export const ControlledMultiple: Story = {
780779
render: () => {
781-
const [selected, setSelected] = React.useState<Selection>(new Set(["california", "texas"]));
782-
783-
const selectedItems = Array.from(selected);
780+
const [selected, setSelected] = React.useState<Key[]>(["california", "texas"]);
784781

785782
return (
786783
<div className="space-y-4">
787-
<Select className="w-[256px]" placeholder="Select states" selectionMode="multiple">
784+
<Select
785+
className="w-[256px]"
786+
placeholder="Select states"
787+
selectionMode="multiple"
788+
value={selected}
789+
onChange={(keys) => setSelected(keys as Key[])}
790+
>
788791
<Label>States (controlled multiple)</Label>
789792
<Select.Trigger>
790793
<Select.Value />
791794
<Select.Indicator />
792795
</Select.Trigger>
793796
<Select.Popover>
794-
<ListBox
795-
selectedKeys={selected}
796-
selectionMode="multiple"
797-
onSelectionChange={(keys) => setSelected(keys as Selection)}
798-
>
797+
<ListBox selectionMode="multiple">
799798
<ListBox.Item id="california" textValue="California">
800799
California
801800
<ListBox.ItemIndicator />
@@ -824,7 +823,7 @@ export const ControlledMultiple: Story = {
824823
</Select.Popover>
825824
</Select>
826825
<p className="text-muted text-sm">
827-
Selected: {selectedItems.length > 0 ? selectedItems.join(", ") : "None"}
826+
Selected: {selected.length > 0 ? selected.join(", ") : "None"}
828827
</p>
829828
</div>
830829
);

0 commit comments

Comments
 (0)