Skip to content

Commit eda3b38

Browse files
committed
Enhance Select component: make SelectOption and SelectProps generic for improved type flexibility.
1 parent 0abcba2 commit eda3b38

2 files changed

Lines changed: 12 additions & 13 deletions

File tree

packages/components/package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lambdacurry/forms",
3-
"version": "0.19.5",
3+
"version": "0.20.0",
44
"type": "module",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",
@@ -26,9 +26,7 @@
2626
"import": "./dist/ui/*.js"
2727
}
2828
},
29-
"files": [
30-
"dist"
31-
],
29+
"files": ["dist"],
3230
"scripts": {
3331
"prepublishOnly": "yarn run build",
3432
"build": "vite build",

packages/components/src/ui/select.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { useOverlayTriggerState } from 'react-stately';
55
import { PopoverContent, PopoverTrigger } from './popover';
66
import { cn } from './utils';
77

8-
export interface SelectOption {
8+
export interface SelectOption<T = string> {
99
label: string;
10-
value: string;
10+
value: T;
1111
}
1212

1313
export interface SelectUIComponents {
@@ -22,10 +22,11 @@ export interface SelectUIComponents {
2222
ChevronIcon?: React.ComponentType<React.SVGProps<SVGSVGElement>>;
2323
}
2424

25-
export interface SelectProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'value' | 'onChange'> {
26-
options: SelectOption[];
27-
value?: string;
28-
onValueChange?: (value: string) => void;
25+
export interface SelectProps<T = string>
26+
extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'value' | 'onChange'> {
27+
options: SelectOption<T>[];
28+
value?: T;
29+
onValueChange?: (value: T) => void;
2930
placeholder?: string;
3031
disabled?: boolean;
3132
className?: string;
@@ -34,7 +35,7 @@ export interface SelectProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonE
3435
components?: Partial<SelectUIComponents>;
3536
}
3637

37-
export function Select({
38+
export function Select<T = string>({
3839
options,
3940
value,
4041
onValueChange,
@@ -45,7 +46,7 @@ export function Select({
4546
itemClassName,
4647
components,
4748
...buttonProps
48-
}: SelectProps) {
49+
}: SelectProps<T>) {
4950
const popoverState = useOverlayTriggerState({});
5051
const listboxId = React.useId();
5152
const [query, setQuery] = React.useState('');
@@ -174,7 +175,7 @@ export function Select({
174175
const isSelected = option.value === value;
175176
const isEnterCandidate = query.trim() !== '' && enterCandidate?.value === option.value && !isSelected;
176177
return (
177-
<li key={option.value} className="list-none">
178+
<li key={String(option.value)} className="list-none">
178179
<Item
179180
ref={isSelected ? selectedItemRef : undefined}
180181
onClick={() => {

0 commit comments

Comments
 (0)