@@ -11,7 +11,9 @@ import { useFormFieldContext } from "../hooks/form-field-context";
1111import { useCustomize } from "../hooks/customization-context" ;
1212import type { BaseReactSelectProps } from "../hooks/customization-context" ;
1313import { LoadMoreButton } from "./LoadMoreButton" ;
14- import { isString , isOptionWithValue , OptionWithValue } from "../utils/type-guards" ;
14+ import {
15+ isString , isOptionWithValue , OptionWithValue ,
16+ } from "../utils/type-guards" ;
1517
1618// XXX T and ConfigurableProp should be related
1719type ControlSelectProps < T > = {
@@ -43,37 +45,37 @@ export function ControlSelect<T>({
4345
4446 useEffect ( ( ) => {
4547 // Ensure all options have proper primitive values for label/value
46- const sanitizedOptions = options . map ( option => {
47- if ( typeof option === ' string' ) return option ;
48-
48+ const sanitizedOptions = options . map ( ( option ) => {
49+ if ( typeof option === " string" ) return option ;
50+
4951 // If option has __lv wrapper, extract the inner option
50- if ( option && typeof option === ' object' && ' __lv' in option ) {
52+ if ( option && typeof option === " object" && " __lv" in option ) {
5153 const innerOption = option . __lv ;
5254 return {
53- label : String ( innerOption ?. label || innerOption ?. value || '' ) ,
54- value : innerOption ?. value
55+ label : String ( innerOption ?. label || innerOption ?. value || "" ) ,
56+ value : innerOption ?. value ,
5557 } ;
5658 }
57-
59+
5860 // Handle nested label and value objects
59- let actualLabel = '' ;
61+ let actualLabel = "" ;
6062 let actualValue = option . value ;
61-
63+
6264 // Extract nested label
63- if ( option . label && typeof option . label === ' object' && ' label' in option . label ) {
64- actualLabel = String ( option . label . label || '' ) ;
65+ if ( option . label && typeof option . label === " object" && " label" in option . label ) {
66+ actualLabel = String ( option . label . label || "" ) ;
6567 } else {
66- actualLabel = String ( option . label || option . value || '' ) ;
68+ actualLabel = String ( option . label || option . value || "" ) ;
6769 }
68-
70+
6971 // Extract nested value
70- if ( option . value && typeof option . value === ' object' && ' value' in option . value ) {
72+ if ( option . value && typeof option . value === " object" && " value" in option . value ) {
7173 actualValue = option . value . value ;
7274 }
73-
75+
7476 return {
7577 label : actualLabel ,
76- value : actualValue
78+ value : actualValue ,
7779 } ;
7880 } ) ;
7981 setSelectOptions ( sanitizedOptions )
@@ -160,7 +162,7 @@ export function ControlSelect<T>({
160162 }
161163
162164 const props = select . getProps ( "controlSelect" , baseSelectProps )
163-
165+
164166 if ( showLoadMoreButton ) {
165167 props . components = {
166168 // eslint-disable-next-line react/prop-types
@@ -180,19 +182,25 @@ export function ControlSelect<T>({
180182 }
181183 const newOption = createOption ( inputValue )
182184 let newRawValue = newOption
183-
185+
184186 // NEVER add wrapped objects to selectOptions - only clean {label, value} objects
185- const cleanSelectOptions = selectOptions . map ( opt => {
186- if ( typeof opt === 'string' ) return opt ;
187- if ( opt && typeof opt === 'object' && '__lv' in opt ) {
188- return { label : String ( opt . __lv ?. label || '' ) , value : opt . __lv ?. value } ;
187+ const cleanSelectOptions = selectOptions . map ( ( opt ) => {
188+ if ( typeof opt === "string" ) return opt ;
189+ if ( opt && typeof opt === "object" && "__lv" in opt ) {
190+ return {
191+ label : String ( opt . __lv ?. label || "" ) ,
192+ value : opt . __lv ?. value ,
193+ } ;
189194 }
190195 return opt ;
191196 } ) ;
192-
193- const newSelectOptions = [ newOption , ...cleanSelectOptions ] ;
197+
198+ const newSelectOptions = [
199+ newOption ,
200+ ...cleanSelectOptions ,
201+ ] ;
194202 setSelectOptions ( newSelectOptions ) ;
195-
203+
196204 if ( prop . type . endsWith ( "[]" ) ) {
197205 if ( Array . isArray ( rawValue ) ) {
198206 newRawValue = [
@@ -242,33 +250,32 @@ export function ControlSelect<T>({
242250 : Select ;
243251
244252 // Final safety check - ensure NO __lv wrapped objects reach react-select
245- const cleanedOptions = selectOptions . map ( opt => {
246- if ( typeof opt === ' string' ) return opt ;
247- if ( opt && typeof opt === ' object' && ' __lv' in opt && opt . __lv ) {
248- let actualLabel = '' ;
253+ const cleanedOptions = selectOptions . map ( ( opt ) => {
254+ if ( typeof opt === " string" ) return opt ;
255+ if ( opt && typeof opt === " object" && " __lv" in opt && opt . __lv ) {
256+ let actualLabel = "" ;
249257 let actualValue = opt . __lv . value ;
250-
258+
251259 // Handle nested label in __lv
252- if ( opt . __lv . label && typeof opt . __lv . label === ' object' && ' label' in opt . __lv . label ) {
253- actualLabel = String ( opt . __lv . label . label || '' ) ;
260+ if ( opt . __lv . label && typeof opt . __lv . label === " object" && " label" in opt . __lv . label ) {
261+ actualLabel = String ( opt . __lv . label . label || "" ) ;
254262 } else {
255- actualLabel = String ( opt . __lv . label || opt . __lv . value || '' ) ;
263+ actualLabel = String ( opt . __lv . label || opt . __lv . value || "" ) ;
256264 }
257-
265+
258266 // Handle nested value in __lv
259- if ( opt . __lv . value && typeof opt . __lv . value === ' object' && ' value' in opt . __lv . value ) {
267+ if ( opt . __lv . value && typeof opt . __lv . value === " object" && " value" in opt . __lv . value ) {
260268 actualValue = opt . __lv . value . value ;
261269 }
262-
270+
263271 return {
264272 label : actualLabel ,
265- value : actualValue
273+ value : actualValue ,
266274 } ;
267275 }
268276 return opt ;
269277 } ) ;
270278
271-
272279 return (
273280 < MaybeCreatableSelect
274281 inputId = { id }
@@ -279,10 +286,14 @@ export function ControlSelect<T>({
279286 isClearable = { true }
280287 required = { ! prop . optional }
281288 getOptionLabel = { ( option ) => {
282- return typeof option === 'string' ? option : String ( option ?. label || option ?. value || '' ) ;
289+ return typeof option === "string"
290+ ? option
291+ : String ( option ?. label || option ?. value || "" ) ;
283292 } }
284293 getOptionValue = { ( option ) => {
285- return typeof option === 'string' ? option : String ( option ?. value || '' ) ;
294+ return typeof option === "string"
295+ ? option
296+ : String ( option ?. value || "" ) ;
286297 } }
287298 onChange = { handleChange }
288299 { ...props }
0 commit comments