Skip to content

Commit 09679d9

Browse files
authored
Multi select list box + dropdown examples (#44)
1 parent 99b2691 commit 09679d9

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

stories/Dropdown.stories.tsx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import {
1111
Button,
1212
Radio,
1313
RadioGroup,
14+
ListBox,
15+
Item,
1416
} from '../src';
1517

1618
const meta: Meta = {
@@ -154,3 +156,41 @@ export const Controlled = () => {
154156
</Provider>
155157
);
156158
};
159+
160+
export const DropdownWithListBox = () => {
161+
const [isOpen, setIsOpen] = useState<boolean>(false);
162+
const [selectedKeys, setSelectedKeys] = useState(['dogs']);
163+
return (
164+
<Provider>
165+
<Dropdown
166+
triggerProps={{
167+
isOpen: isOpen,
168+
onOpenChange: open => setIsOpen(open),
169+
}}
170+
menu={
171+
<ListBox
172+
style={{ width: 200 }}
173+
aria-label="Pick your favorite"
174+
selectionMode="multiple"
175+
selectedKeys={selectedKeys}
176+
onSelectionChange={selected =>
177+
// @ts-ignore we know the keys are strings
178+
setSelectedKeys(Array.from(selected))
179+
}
180+
>
181+
<Item key="Aardvark">Aardvark</Item>
182+
<Item key="Kangaroo">Kangaroo</Item>
183+
<Item key="Snake">Snake</Item>
184+
<Item key="Danni">Danni</Item>
185+
<Item key="Devon">Devon</Item>
186+
<Item key="Ross">Ross</Item>
187+
</ListBox>
188+
}
189+
>
190+
{selectedKeys.length < 2
191+
? selectedKeys.join(', ')
192+
: `${selectedKeys.length} selected`}
193+
</Dropdown>
194+
</Provider>
195+
);
196+
};

stories/ListBox.stories.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,22 @@ const ListBoxWithSections: Story<ListBoxProps<string>> = args => {
8282
};
8383

8484
export const listBoxWithSections = ListBoxWithSections.bind({});
85+
86+
const ListBoxMultiSelect: Story<ListBoxProps<string>> = args => {
87+
return (
88+
<ListBox
89+
style={{ width: 200 }}
90+
aria-label="Pick your favorite"
91+
selectionMode="multiple"
92+
>
93+
<Item key="Aardvark">Aardvark</Item>
94+
<Item key="Kangaroo">Kangaroo</Item>
95+
<Item key="Snake">Snake</Item>
96+
<Item key="Danni">Danni</Item>
97+
<Item key="Devon">Devon</Item>
98+
<Item key="Ross">Ross</Item>
99+
</ListBox>
100+
);
101+
};
102+
103+
export const listBoxMultiSelect = ListBoxMultiSelect.bind({});

0 commit comments

Comments
 (0)