@@ -20,6 +20,12 @@ const dSelectWarning = 'd-select-warning'
2020const dSelectError = 'd-select-error'
2121const dFloatingLabel = 'd-floating-label'
2222
23+ export interface SelectOption {
24+ label : React . ReactNode
25+ value : string | number
26+ disabled ?: boolean
27+ }
28+
2329export interface SelectProps extends Omit < React . SelectHTMLAttributes < HTMLSelectElement > , 'size' > {
2430 size ?: 'xs' | 'sm' | 'md' | 'lg' | 'xl'
2531 color ?: 'neutral' | 'primary' | 'secondary' | 'accent' | 'info' | 'success' | 'warning' | 'error'
@@ -33,6 +39,8 @@ export interface SelectProps extends Omit<React.SelectHTMLAttributes<HTMLSelectE
3339 addonBefore ?: React . ReactNode
3440 /** Text/element after select (outside, using DaisyUI label) */
3541 addonAfter ?: React . ReactNode
42+ /** Select options array (recommended for better performance) */
43+ options ?: SelectOption [ ]
3644 className ?: string
3745 children ?: React . ReactNode
3846 'data-testid' ?: string
@@ -49,6 +57,7 @@ export const Select = forwardRef<HTMLSelectElement, SelectProps>(
4957 floatingLabel,
5058 addonBefore,
5159 addonAfter,
60+ options,
5261 className = '' ,
5362 children,
5463 'data-testid' : testId ,
@@ -59,6 +68,18 @@ export const Select = forwardRef<HTMLSelectElement, SelectProps>(
5968 const { componentSize } = useConfig ( )
6069 const effectiveSize = size ?? componentSize ?? 'md'
6170
71+ // Render options from array or use children
72+ const renderOptions = ( ) => {
73+ if ( options ) {
74+ return options . map ( ( option ) => (
75+ < option key = { option . value } value = { option . value } disabled = { option . disabled } >
76+ { option . label }
77+ </ option >
78+ ) )
79+ }
80+ return children
81+ }
82+
6283 const innerRef = useRef < HTMLSelectElement > ( null )
6384 const selectRef = ( ref as React . RefObject < HTMLSelectElement > ) || innerRef
6485
@@ -110,7 +131,7 @@ export const Select = forwardRef<HTMLSelectElement, SelectProps>(
110131 // Build the core select element
111132 const selectElement = (
112133 < select ref = { selectRef } className = { selectClasses } data-testid = { selectTestId } { ...props } >
113- { children }
134+ { renderOptions ( ) }
114135 </ select >
115136 )
116137
@@ -129,7 +150,7 @@ export const Select = forwardRef<HTMLSelectElement, SelectProps>(
129150 data-testid = { selectTestId }
130151 { ...props }
131152 >
132- { children }
153+ { renderOptions ( ) }
133154 </ select >
134155 < span > { floatingLabel } </ span >
135156 </ label >
0 commit comments