@@ -11,7 +11,6 @@ import React, {
1111import classnames from 'classnames' ;
1212import { FormElement , FormElementProps } from './FormElement' ;
1313import { Icon } from './Icon' ;
14- import { Button , ButtonProps } from './Button' ;
1514import {
1615 DropdownMenu ,
1716 DropdownMenuItem ,
@@ -55,6 +54,8 @@ const PicklistContext = createContext<{
5554 *
5655 */
5756export type PicklistProps < MultiSelect extends boolean | undefined > = {
57+ id ?: string ;
58+ className ?: string ;
5859 label ?: string ;
5960 required ?: boolean ;
6061 multiSelect ?: MultiSelect ;
@@ -84,10 +85,8 @@ export type PicklistProps<MultiSelect extends boolean | undefined> = {
8485 onKeyDown ?: ( e : React . KeyboardEvent ) => void ;
8586 onBlur ?: ( ) => void ;
8687 onComplete ?: ( ) => void ;
87- } & Omit <
88- ButtonProps ,
89- 'type' | 'value' | 'defaultValue' | 'onSelect' | 'onBlur' | 'onKeyDown'
90- > ;
88+ children ?: React . ReactNode ;
89+ } ;
9190
9291/**
9392 *
@@ -116,7 +115,6 @@ export const Picklist: (<MultiSelect extends boolean | undefined>(
116115 tooltip,
117116 tooltipIcon,
118117 elementRef : elementRef_ ,
119- buttonRef : buttonRef_ ,
120118 dropdownRef : dropdownRef_ ,
121119 onSelect,
122120 onComplete,
@@ -162,8 +160,7 @@ export const Picklist: (<MultiSelect extends boolean | undefined>(
162160
163161 const elRef = useRef < HTMLDivElement | null > ( null ) ;
164162 const elementRef = useMergeRefs ( [ elRef , elementRef_ ] ) ;
165- const buttonElRef = useRef < HTMLButtonElement | null > ( null ) ;
166- const buttonRef = useMergeRefs ( [ buttonElRef , buttonRef_ ] ) ;
163+ const comboboxElRef = useRef < HTMLDivElement | null > ( null ) ;
167164 const dropdownElRef = useRef < HTMLDivElement | null > ( null ) ;
168165 const dropdownRef = useMergeRefs ( [ dropdownElRef , dropdownRef_ ] ) ;
169166
@@ -197,6 +194,11 @@ export const Picklist: (<MultiSelect extends boolean | undefined>(
197194 } else {
198195 // set only one value
199196 setPicklistValues ( [ itemValue ] ) ;
197+ setOpened ( false ) ;
198+ setTimeout ( ( ) => {
199+ comboboxElRef . current ?. focus ( ) ;
200+ onComplete ?.( ) ;
201+ } , 10 ) ;
200202 }
201203 } ) ;
202204
@@ -223,29 +225,14 @@ export const Picklist: (<MultiSelect extends boolean | undefined>(
223225 } ) ;
224226
225227 const onClick = useEventCallback ( ( ) => {
226- setOpened ( ( opened ) => ! opened ) ;
227- setTimeout ( ( ) => {
228- focusToTargetItemEl ( ) ;
229- } , 10 ) ;
228+ if ( ! disabled ) {
229+ setOpened ( ( opened ) => ! opened ) ;
230+ }
230231 } ) ;
231232
232233 const onPicklistItemSelect = useEventCallback ( ( value : PicklistValue ) => {
233234 updateItemValue ( value ) ;
234235 onSelect ?.( value ) ;
235- if ( ! multiSelect ) {
236- // close if only single select
237- setTimeout ( ( ) => {
238- setOpened ( false ) ;
239- onComplete ?.( ) ;
240- buttonElRef . current ?. focus ( ) ;
241- } , 200 ) ;
242- }
243- } ) ;
244-
245- const onPicklistClose = useEventCallback ( ( ) => {
246- buttonElRef . current ?. focus ( ) ;
247- setOpened ( false ) ;
248- onComplete ?.( ) ;
249236 } ) ;
250237
251238 const onBlur = useEventCallback ( ( ) => {
@@ -284,7 +271,7 @@ export const Picklist: (<MultiSelect extends boolean | undefined>(
284271 function getSelectedItemLabel ( ) {
285272 // many items selected
286273 if ( values . length > 1 ) {
287- return optionsSelectedText ;
274+ return ` ${ values . length } ${ optionsSelectedText } ` ;
288275 }
289276
290277 // one item
@@ -356,34 +343,28 @@ export const Picklist: (<MultiSelect extends boolean | undefined>(
356343 className = 'slds-combobox__form-element slds-input-has-icon slds-input-has-icon_right'
357344 role = 'none'
358345 >
359- < Button
360- id = { id }
361- buttonRef = { buttonRef }
362- { ...rprops }
363- className = { inputClassNames }
364- style = { { justifyContent : 'normal' } }
365- type = 'neutral'
366- disabled = { disabled }
367- onClick = { disabled ? undefined : onClick }
368- onBlur = { disabled ? undefined : onBlur }
369- onKeyDown = { disabled ? undefined : onKeydown }
346+ < div
347+ ref = { comboboxElRef }
370348 role = 'combobox'
371349 tabIndex = { disabled ? - 1 : 0 }
350+ className = { inputClassNames }
372351 aria-controls = { listboxId }
373352 aria-expanded = { opened }
374353 aria-haspopup = 'listbox'
375354 aria-disabled = { disabled }
355+ onClick = { onClick }
356+ onKeyDown = { onKeydown }
357+ onBlur = { onBlur }
358+ { ...rprops }
376359 >
377360 < span className = 'slds-truncate' > { getSelectedItemLabel ( ) } </ span >
378- < div >
379- < Icon
380- container = { true }
381- containerClassName = 'slds-icon-utility-down slds-input__icon slds-input__icon_right'
382- icon = 'down'
383- className = 'slds-icon slds-icon_x-small slds-icon-text-default'
384- />
385- </ div >
386- </ Button >
361+ </ div >
362+ < span className = 'slds-icon_container slds-icon-utility-down slds-input__icon slds-input__icon_right' >
363+ < Icon
364+ icon = 'down'
365+ className = 'slds-icon slds-icon_x-small slds-icon-text-default'
366+ />
367+ </ span >
387368 </ div >
388369 { opened && (
389370 < DropdownMenu
@@ -392,7 +373,10 @@ export const Picklist: (<MultiSelect extends boolean | undefined>(
392373 size = { menuSize }
393374 style = { menuStyle }
394375 onMenuSelect = { onPicklistItemSelect }
395- onMenuClose = { onPicklistClose }
376+ onMenuClose = { ( ) => {
377+ setOpened ( false ) ;
378+ onComplete ?.( ) ;
379+ } }
396380 onBlur = { onBlur }
397381 >
398382 < PicklistContext . Provider value = { contextValue } >
0 commit comments