diff --git a/src/scripts/Picklist.tsx b/src/scripts/Picklist.tsx index 609caf826..09de07b23 100644 --- a/src/scripts/Picklist.tsx +++ b/src/scripts/Picklist.tsx @@ -173,6 +173,7 @@ export type PicklistProps = { tooltip?: ReactNode; tooltipIcon?: string; elementRef?: Ref; + inputRef?: Ref; dropdownRef?: Ref; onValueChange?: Bivariant< ( @@ -214,6 +215,7 @@ export const Picklist: (( tooltip, tooltipIcon, elementRef: elementRef_, + inputRef: inputRef_, dropdownRef: dropdownRef_, onSelect, onComplete, @@ -336,6 +338,7 @@ export const Picklist: (( const elRef = useRef(null); const elementRef = useMergeRefs([elRef, elementRef_]); const comboboxElRef = useRef(null); + const inputRef = useMergeRefs([comboboxElRef, inputRef_]); const dropdownElRef = useRef(null); const dropdownRef = useMergeRefs([dropdownElRef, dropdownRef_]); @@ -559,7 +562,7 @@ export const Picklist: (( role='none' >
( > {selectedItemLabel}
- - - + {opened && (
void; children?: React.ReactNode; }; @@ -634,6 +642,10 @@ export const PicklistItem: FC = ({ selected: selected_, value, disabled, + icon, + iconRight, + divider, + onClick: onClick_, children, }) => { const { values, multiSelect, onSelect, focusedValue, optionIdPrefix } = @@ -642,9 +654,10 @@ export const PicklistItem: FC = ({ selected_ ?? (value != null ? values.indexOf(value) >= 0 : false); const isFocused = focusedValue === value; - const onClick = useEventCallback(() => { + const onClick = useEventCallback((e: React.SyntheticEvent) => { if (!disabled && value != null) { onSelect(value); + onClick_?.(e); } }); @@ -659,8 +672,12 @@ export const PicklistItem: FC = ({ } ); - return ( -
  • + const listItemClassNames = classnames( + 'slds-listbox__item', + divider ? `slds-has-divider_${divider}-space` : undefined + ); + const mainListItem = ( +
  • = ({ onClick={onClick} > - {selected && ( - - - - )} + {icon ? ( + + ) : selected ? ( + + ) : null} {label || children} + {iconRight && ( + + + + )}
  • ); + + return ( + <> + {divider === 'top' && ( +
  • + )} + {mainListItem} + {divider === 'bottom' && ( +
  • + )} + + ); };