@@ -17,7 +17,7 @@ import { FormElement, FormElementProps } from './FormElement';
1717import { Icon } from './Icon' ;
1818import { AutoAlign , RectangleAlignment } from './AutoAlign' ;
1919import { DropdownMenuProps } from './DropdownMenu' ;
20- import { registerStyle , isElInChildren } from './util' ;
20+ import { isElInChildren } from './util' ;
2121import { ComponentSettingsContext } from './ComponentSettings' ;
2222import { useControlledValue , useEventCallback , useMergeRefs } from './hooks' ;
2323import { createFC } from './common' ;
@@ -67,7 +67,7 @@ function collectOptionValues(children: unknown): PicklistValue[] {
6767function findSelectedItemLabel (
6868 children : unknown ,
6969 selectedValue : PicklistValue
70- ) : string | number | null {
70+ ) : React . ReactNode | null {
7171 return (
7272 React . Children . map ( children , ( child ) => {
7373 if ( ! React . isValidElement ( child ) ) {
@@ -107,56 +107,21 @@ function findSelectedItemLabel(
107107 typeof label === 'string' ||
108108 typeof label === 'number' ||
109109 React . isValidElement ( label )
110- ? extractTextContent ( label )
110+ ? label
111111 : undefined ;
112112 const childrenValue =
113113 typeof itemChildren === 'string' ||
114114 typeof itemChildren === 'number' ||
115115 React . isValidElement ( itemChildren ) ||
116116 Array . isArray ( itemChildren )
117- ? extractTextContent ( itemChildren )
117+ ? itemChildren
118118 : undefined ;
119119
120120 return labelValue || childrenValue ;
121121 } ) . find ( ( result ) => result !== null ) ?? null
122122 ) ;
123123}
124124
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-
160125/**
161126 *
162127 */
@@ -185,17 +150,6 @@ const PicklistContext = createContext<{
185150 optionIdPrefix : '' ,
186151} ) ;
187152
188- /**
189- *
190- */
191- function useInitComponentStyle ( ) {
192- useEffect ( ( ) => {
193- registerStyle ( 'picklist' , [
194- [ '.react-picklist-input:not(:disabled)' , '{ cursor: pointer; }' ] ,
195- ] ) ;
196- } , [ ] ) ;
197- }
198-
199153/**
200154 *
201155 */
@@ -220,7 +174,7 @@ export type PicklistProps<MultiSelect extends boolean | undefined> = {
220174 tooltip ?: ReactNode ;
221175 tooltipIcon ?: string ;
222176 elementRef ?: Ref < HTMLDivElement > ;
223- inputRef ?: Ref < HTMLInputElement > ;
177+ buttonRef ?: Ref < HTMLButtonElement > ;
224178 dropdownRef ?: Ref < HTMLDivElement > ;
225179 onValueChange ?: Bivariant <
226180 (
@@ -262,7 +216,7 @@ export const Picklist: (<MultiSelect extends boolean | undefined>(
262216 tooltip,
263217 tooltipIcon,
264218 elementRef : elementRef_ ,
265- inputRef : inputRef_ ,
219+ buttonRef : buttonRef_ ,
266220 dropdownRef : dropdownRef_ ,
267221 onSelect,
268222 onComplete,
@@ -273,8 +227,6 @@ export const Picklist: (<MultiSelect extends boolean | undefined>(
273227 ...rprops
274228 } = props ;
275229
276- useInitComponentStyle ( ) ;
277-
278230 const fallbackId = useId ( ) ;
279231 const id = id_ ?? fallbackId ;
280232 const listboxId = `${ id } -listbox` ;
@@ -386,8 +338,8 @@ export const Picklist: (<MultiSelect extends boolean | undefined>(
386338
387339 const elRef = useRef < HTMLDivElement | null > ( null ) ;
388340 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_ ] ) ;
391343 const dropdownElRef = useRef < HTMLDivElement | null > ( null ) ;
392344 const dropdownRef = useMergeRefs ( [ dropdownElRef , dropdownRef_ ] ) ;
393345
@@ -570,7 +522,6 @@ export const Picklist: (<MultiSelect extends boolean | undefined>(
570522 }
571523 ) ;
572524 const inputClassNames = classnames (
573- 'react-picklist-input' ,
574525 'slds-input_faux' ,
575526 'slds-combobox__input' ,
576527 {
@@ -621,9 +572,9 @@ export const Picklist: (<MultiSelect extends boolean | undefined>(
621572 className = 'slds-combobox__form-element slds-input-has-icon slds-input-has-icon_right'
622573 role = 'none'
623574 >
624- < input
625- type = 'text '
626- ref = { inputRef }
575+ < button
576+ type = 'button '
577+ ref = { buttonRef }
627578 role = 'combobox'
628579 tabIndex = { disabled ? - 1 : 0 }
629580 className = { inputClassNames }
@@ -637,11 +588,11 @@ export const Picklist: (<MultiSelect extends boolean | undefined>(
637588 onClick = { onClick }
638589 onKeyDown = { onKeyDown }
639590 onBlur = { onBlur }
640- { ...rprops }
641- value = { selectedItemLabel }
642- readOnly
643591 disabled = { disabled }
644- />
592+ { ...rprops }
593+ >
594+ < span className = 'slds-truncate' > { selectedItemLabel } </ span >
595+ </ button >
645596 < Icon
646597 containerClassName = 'slds-input__icon slds-input__icon_right'
647598 category = 'utility'
0 commit comments