Skip to content

Commit 930e644

Browse files
committed
Update multi select
1 parent bfbaa03 commit 930e644

4 files changed

Lines changed: 101 additions & 161 deletions

File tree

src/list-box.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export const ListBoxItem = React.forwardRef(
4949
'group relative flex outline-0',
5050
isDisabled && 'opacity-50',
5151
isFocusVisible &&
52-
'outline-ring outline outline-2 outline-offset-2',
52+
'outline-ring outline-2 outline-offset-2',
5353
className,
5454
),
5555
)}

src/select.tsx

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import {
66
Button,
77
ButtonProps as RACButtonProps,
88
ListBoxItemProps,
9-
SelectValue,
9+
SelectValue as RACSelectValue,
1010
composeRenderProps,
1111
Collection,
1212
ListBoxSectionProps as RACListBoxSectionProps,
1313
ListBoxSection as RACListBoxSection,
1414
ListBoxItem as RACListBoxItem,
15+
SelectValueProps,
1516
} from 'react-aria-components';
1617
import { ListBoxProps, ListBox } from './list-box';
1718
import { Popover, PopoverProps } from './popover';
@@ -21,7 +22,9 @@ import { Small } from './text';
2122
import { CheckIcon } from './icons/outline/check';
2223
import { ChevronDownIcon } from './icons/outline/chevron-down';
2324

24-
export function Select<T extends object>(props: RACSelectProps<T, 'single' | 'multiple'>) {
25+
export function Select<T extends object>(
26+
props: RACSelectProps<T, 'single' | 'multiple'>,
27+
) {
2528
return (
2629
<RACSelect
2730
{...props}
@@ -36,15 +39,20 @@ export function Select<T extends object>(props: RACSelectProps<T, 'single' | 'mu
3639

3740
export function SelectButton({
3841
children,
42+
ref,
3943
buttonArrow = <ChevronDownIcon className="text-muted size-5 sm:size-4" />,
44+
selectValue,
4045
...props
4146
}: RACButtonProps & {
47+
ref?: React.ForwardedRef<HTMLButtonElement>;
4248
children?: React.ReactNode;
4349
buttonArrow?: React.ReactNode;
50+
selectValue?: React.ReactNode;
4451
}) {
4552
return (
4653
<Button
4754
{...props}
55+
ref={ref}
4856
data-ui="control"
4957
className={composeRenderProps(
5058
props.className,
@@ -70,9 +78,22 @@ export function SelectButton({
7078
{!!children && (
7179
<span className="flex items-center gap-x-2">{children}</span>
7280
)}
73-
<SelectValue
74-
data-ui="select-value"
75-
className={twMerge([
81+
{selectValue === undefined ? <SelectValue /> : selectValue}
82+
83+
{buttonArrow}
84+
</Button>
85+
);
86+
}
87+
88+
export function SelectValue<T extends object>({
89+
className,
90+
...props
91+
}: SelectValueProps<T>) {
92+
return (
93+
<RACSelectValue
94+
data-ui="select-value"
95+
className={composeRenderProps(className, (className) => {
96+
return twMerge([
7697
'data-placeholder:text-muted flex-1 truncate dark:data-placeholder:text-white',
7798
// Selected Item style
7899
'*:data-[ui=content]:flex',
@@ -84,11 +105,11 @@ export function SelectButton({
84105
'[&>[data-ui=content]_[role=img]]:size-6',
85106
'sm:[&>[data-ui=content]_[data-ui=icon]:not([class*=size-])]:size-4',
86107
'sm:[&>[data-ui=content]_[role=img]]:size-5',
87-
])}
88-
/>
89-
90-
{buttonArrow}
91-
</Button>
108+
className,
109+
]);
110+
})}
111+
{...props}
112+
/>
92113
);
93114
}
94115

stories/MultiSelection.mdx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ import * as MultiSelectionStories from './MultiSelection.stories';
66

77
# Multiple selection
88

9-
Multiple selection can be implemented using the <a href="https://react-spectrum.adobe.com/react-aria/Autocomplete.html#autocomplete" target="_blank">**autocomplete**</a>.
9+
Multiple selection can be implemented using <a href="https://react-spectrum.adobe.com/react-aria/Select.html" target="_blank">**Select**</a> and <a href="https://react-spectrum.adobe.com/react-aria/Autocomplete.html#autocomplete" target="_blank">**Autocomplete**</a>.
1010

1111
<Canvas of={MultiSelectionStories.BasicExample} />
12-
13-
## Inline
14-
15-
<Canvas of={MultiSelectionStories.Inline} />

0 commit comments

Comments
 (0)