@@ -17,7 +17,7 @@ import { FormElement, FormElementProps } from './FormElement';
17
17
import { Icon } from './Icon' ;
18
18
import { AutoAlign , RectangleAlignment } from './AutoAlign' ;
19
19
import { DropdownMenuProps } from './DropdownMenu' ;
20
- import { registerStyle , isElInChildren } from './util' ;
20
+ import { isElInChildren } from './util' ;
21
21
import { ComponentSettingsContext } from './ComponentSettings' ;
22
22
import { useControlledValue , useEventCallback , useMergeRefs } from './hooks' ;
23
23
import { createFC } from './common' ;
@@ -67,7 +67,7 @@ function collectOptionValues(children: unknown): PicklistValue[] {
67
67
function findSelectedItemLabel (
68
68
children : unknown ,
69
69
selectedValue : PicklistValue
70
- ) : string | number | null {
70
+ ) : React . ReactNode | null {
71
71
return (
72
72
React . Children . map ( children , ( child ) => {
73
73
if ( ! React . isValidElement ( child ) ) {
@@ -107,56 +107,21 @@ function findSelectedItemLabel(
107
107
typeof label === 'string' ||
108
108
typeof label === 'number' ||
109
109
React . isValidElement ( label )
110
- ? extractTextContent ( label )
110
+ ? label
111
111
: undefined ;
112
112
const childrenValue =
113
113
typeof itemChildren === 'string' ||
114
114
typeof itemChildren === 'number' ||
115
115
React . isValidElement ( itemChildren ) ||
116
116
Array . isArray ( itemChildren )
117
- ? extractTextContent ( itemChildren )
117
+ ? itemChildren
118
118
: undefined ;
119
119
120
120
return labelValue || childrenValue ;
121
121
} ) . find ( ( result ) => result !== null ) ?? null
122
122
) ;
123
123
}
124
124
125
- /**
126
- * Extract text content from React node recursively
127
- */
128
- function extractTextContent ( node : unknown ) : string | number | null {
129
- if ( node == null ) {
130
- return null ;
131
- }
132
-
133
- if ( typeof node === 'string' || typeof node === 'number' ) {
134
- return node ;
135
- }
136
-
137
- if ( typeof node === 'boolean' ) {
138
- return String ( node ) ;
139
- }
140
-
141
- if ( Array . isArray ( node ) ) {
142
- return node
143
- . map ( extractTextContent )
144
- . filter ( ( result ) => result !== null )
145
- . join ( '' ) ;
146
- }
147
-
148
- if (
149
- React . isValidElement ( node ) &&
150
- node . props &&
151
- typeof node . props === 'object' &&
152
- 'children' in node . props
153
- ) {
154
- return extractTextContent ( node . props . children ) ;
155
- }
156
-
157
- return null ;
158
- }
159
-
160
125
/**
161
126
*
162
127
*/
@@ -185,17 +150,6 @@ const PicklistContext = createContext<{
185
150
optionIdPrefix : '' ,
186
151
} ) ;
187
152
188
- /**
189
- *
190
- */
191
- function useInitComponentStyle ( ) {
192
- useEffect ( ( ) => {
193
- registerStyle ( 'picklist' , [
194
- [ '.react-picklist-input:not(:disabled)' , '{ cursor: pointer; }' ] ,
195
- ] ) ;
196
- } , [ ] ) ;
197
- }
198
-
199
153
/**
200
154
*
201
155
*/
@@ -220,7 +174,7 @@ export type PicklistProps<MultiSelect extends boolean | undefined> = {
220
174
tooltip ?: ReactNode ;
221
175
tooltipIcon ?: string ;
222
176
elementRef ?: Ref < HTMLDivElement > ;
223
- inputRef ?: Ref < HTMLInputElement > ;
177
+ buttonRef ?: Ref < HTMLButtonElement > ;
224
178
dropdownRef ?: Ref < HTMLDivElement > ;
225
179
onValueChange ?: Bivariant <
226
180
(
@@ -262,7 +216,7 @@ export const Picklist: (<MultiSelect extends boolean | undefined>(
262
216
tooltip,
263
217
tooltipIcon,
264
218
elementRef : elementRef_ ,
265
- inputRef : inputRef_ ,
219
+ buttonRef : buttonRef_ ,
266
220
dropdownRef : dropdownRef_ ,
267
221
onSelect,
268
222
onComplete,
@@ -273,8 +227,6 @@ export const Picklist: (<MultiSelect extends boolean | undefined>(
273
227
...rprops
274
228
} = props ;
275
229
276
- useInitComponentStyle ( ) ;
277
-
278
230
const fallbackId = useId ( ) ;
279
231
const id = id_ ?? fallbackId ;
280
232
const listboxId = `${ id } -listbox` ;
@@ -386,8 +338,8 @@ export const Picklist: (<MultiSelect extends boolean | undefined>(
386
338
387
339
const elRef = useRef < HTMLDivElement | null > ( null ) ;
388
340
const elementRef = useMergeRefs ( [ elRef , elementRef_ ] ) ;
389
- const comboboxElRef = useRef < HTMLInputElement | null > ( null ) ;
390
- const inputRef = useMergeRefs ( [ comboboxElRef , inputRef_ ] ) ;
341
+ const comboboxElRef = useRef < HTMLButtonElement | null > ( null ) ;
342
+ const buttonRef = useMergeRefs ( [ comboboxElRef , buttonRef_ ] ) ;
391
343
const dropdownElRef = useRef < HTMLDivElement | null > ( null ) ;
392
344
const dropdownRef = useMergeRefs ( [ dropdownElRef , dropdownRef_ ] ) ;
393
345
@@ -570,7 +522,6 @@ export const Picklist: (<MultiSelect extends boolean | undefined>(
570
522
}
571
523
) ;
572
524
const inputClassNames = classnames (
573
- 'react-picklist-input' ,
574
525
'slds-input_faux' ,
575
526
'slds-combobox__input' ,
576
527
{
@@ -621,9 +572,9 @@ export const Picklist: (<MultiSelect extends boolean | undefined>(
621
572
className = 'slds-combobox__form-element slds-input-has-icon slds-input-has-icon_right'
622
573
role = 'none'
623
574
>
624
- < input
625
- type = 'text '
626
- ref = { inputRef }
575
+ < button
576
+ type = 'button '
577
+ ref = { buttonRef }
627
578
role = 'combobox'
628
579
tabIndex = { disabled ? - 1 : 0 }
629
580
className = { inputClassNames }
@@ -637,11 +588,11 @@ export const Picklist: (<MultiSelect extends boolean | undefined>(
637
588
onClick = { onClick }
638
589
onKeyDown = { onKeyDown }
639
590
onBlur = { onBlur }
640
- { ...rprops }
641
- value = { selectedItemLabel }
642
- readOnly
643
591
disabled = { disabled }
644
- />
592
+ { ...rprops }
593
+ >
594
+ < span className = 'slds-truncate' > { selectedItemLabel } </ span >
595
+ </ button >
645
596
< Icon
646
597
containerClassName = 'slds-input__icon slds-input__icon_right'
647
598
category = 'utility'
0 commit comments