|
1 | 1 | 'use client'; |
2 | 2 |
|
3 | 3 | import { ChevronDownIcon } from '@heroicons/react/24/outline'; |
4 | | -import * as Primitive from '@radix-ui/react-select'; |
| 4 | +import * as ScrollPrimitive from '@radix-ui/react-scroll-area'; |
| 5 | +import * as SelectPrimitive from '@radix-ui/react-select'; |
5 | 6 | import classNames from 'classnames'; |
6 | 7 | import { useId, useMemo } from 'react'; |
7 | 8 | import type { FC } from 'react'; |
@@ -77,50 +78,58 @@ const Select: FC<SelectProps> = ({ |
77 | 78 | </label> |
78 | 79 | )} |
79 | 80 |
|
80 | | - <Primitive.Root value={defaultValue} onValueChange={onChange}> |
81 | | - <Primitive.Trigger |
| 81 | + <SelectPrimitive.Root value={defaultValue} onValueChange={onChange}> |
| 82 | + <SelectPrimitive.Trigger |
82 | 83 | className={styles.trigger} |
83 | 84 | aria-label={label} |
84 | 85 | id={id} |
85 | 86 | > |
86 | | - <Primitive.Value placeholder={placeholder} /> |
| 87 | + <SelectPrimitive.Value placeholder={placeholder} /> |
87 | 88 | <ChevronDownIcon className={styles.icon} /> |
88 | | - </Primitive.Trigger> |
89 | | - <Primitive.Portal> |
90 | | - <Primitive.Content |
| 89 | + </SelectPrimitive.Trigger> |
| 90 | + |
| 91 | + <SelectPrimitive.Portal> |
| 92 | + <SelectPrimitive.Content |
91 | 93 | position={inline ? 'popper' : 'item-aligned'} |
92 | 94 | className={classNames(styles.dropdown, { [styles.inline]: inline })} |
93 | 95 | > |
94 | | - <Primitive.Viewport> |
95 | | - {mappedValues.map(({ label, items }, key) => ( |
96 | | - <Primitive.Group key={label?.toString() || key}> |
97 | | - {label && ( |
98 | | - <Primitive.Label |
99 | | - className={classNames(styles.item, styles.label)} |
100 | | - > |
101 | | - {label} |
102 | | - </Primitive.Label> |
103 | | - )} |
104 | | - |
105 | | - {items.map(({ value, label, iconImage, disabled }) => ( |
106 | | - <Primitive.Item |
107 | | - key={value} |
108 | | - value={value} |
109 | | - disabled={disabled} |
110 | | - className={classNames(styles.item, styles.text)} |
111 | | - > |
112 | | - <Primitive.ItemText> |
113 | | - {iconImage} |
114 | | - <span>{label}</span> |
115 | | - </Primitive.ItemText> |
116 | | - </Primitive.Item> |
| 96 | + <ScrollPrimitive.Root type="auto"> |
| 97 | + <SelectPrimitive.Viewport> |
| 98 | + <ScrollPrimitive.Viewport> |
| 99 | + {mappedValues.map(({ label, items }, key) => ( |
| 100 | + <SelectPrimitive.Group key={label?.toString() ?? key}> |
| 101 | + {label && ( |
| 102 | + <SelectPrimitive.Label |
| 103 | + className={classNames(styles.item, styles.label)} |
| 104 | + > |
| 105 | + {label} |
| 106 | + </SelectPrimitive.Label> |
| 107 | + )} |
| 108 | + |
| 109 | + {items.map(({ value, label, iconImage, disabled }) => ( |
| 110 | + <SelectPrimitive.Item |
| 111 | + key={value} |
| 112 | + value={value} |
| 113 | + disabled={disabled} |
| 114 | + className={classNames(styles.item, styles.text)} |
| 115 | + > |
| 116 | + <SelectPrimitive.ItemText> |
| 117 | + {iconImage} |
| 118 | + <span>{label}</span> |
| 119 | + </SelectPrimitive.ItemText> |
| 120 | + </SelectPrimitive.Item> |
| 121 | + ))} |
| 122 | + </SelectPrimitive.Group> |
117 | 123 | ))} |
118 | | - </Primitive.Group> |
119 | | - ))} |
120 | | - </Primitive.Viewport> |
121 | | - </Primitive.Content> |
122 | | - </Primitive.Portal> |
123 | | - </Primitive.Root> |
| 124 | + </ScrollPrimitive.Viewport> |
| 125 | + </SelectPrimitive.Viewport> |
| 126 | + <ScrollPrimitive.Scrollbar orientation="vertical"> |
| 127 | + <ScrollPrimitive.Thumb /> |
| 128 | + </ScrollPrimitive.Scrollbar> |
| 129 | + </ScrollPrimitive.Root> |
| 130 | + </SelectPrimitive.Content> |
| 131 | + </SelectPrimitive.Portal> |
| 132 | + </SelectPrimitive.Root> |
124 | 133 | </span> |
125 | 134 | ); |
126 | 135 | }; |
|
0 commit comments