Skip to content

Commit e1721e4

Browse files
(Picklit): simplify scrolling logic
1 parent dfe1d79 commit e1721e4

File tree

1 file changed

+4
-23
lines changed

1 file changed

+4
-23
lines changed

src/scripts/Picklist.tsx

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -229,27 +229,7 @@ export const Picklist: (<MultiSelect extends boolean | undefined>(
229229
return;
230230
}
231231

232-
// Calculate element position within container
233-
const elementTopPosition = targetElement.offsetTop;
234-
const elementBottomPosition =
235-
elementTopPosition + targetElement.offsetHeight;
236-
237-
// Calculate currently visible area
238-
const currentScrollPosition = dropdownContainer.scrollTop;
239-
const visibleAreaHeight = dropdownContainer.clientHeight;
240-
const visibleAreaTop = currentScrollPosition;
241-
const visibleAreaBottom = currentScrollPosition + visibleAreaHeight;
242-
243-
// Check if element is outside the visible area
244-
const isAbove = elementTopPosition < visibleAreaTop;
245-
const isBelow = elementBottomPosition > visibleAreaBottom;
246-
247-
// Scroll only if element is not currently visible
248-
if (isAbove || isBelow) {
249-
targetElement.scrollIntoView({
250-
block: 'center',
251-
});
252-
}
232+
targetElement.focus();
253233
}
254234
);
255235

@@ -519,8 +499,6 @@ export const Picklist: (<MultiSelect extends boolean | undefined>(
519499
focusedValue ? `${optionIdPrefix}-${focusedValue}` : undefined
520500
}
521501
onClick={onClick}
522-
onKeyDown={onKeyDown}
523-
onBlur={onBlur}
524502
{...rprops}
525503
>
526504
<span className='slds-truncate'>{getSelectedItemLabel()}</span>
@@ -546,6 +524,8 @@ export const Picklist: (<MultiSelect extends boolean | undefined>(
546524
<ul
547525
className='slds-listbox slds-listbox_vertical'
548526
role='presentation'
527+
onKeyDown={onKeyDown}
528+
onBlur={onBlur}
549529
>
550530
<PicklistContext.Provider value={contextValue}>
551531
{children}
@@ -614,6 +594,7 @@ export const PicklistItem: FC<PicklistItemProps> = ({
614594
aria-selected={selected}
615595
aria-checked={multiSelect ? selected : undefined}
616596
aria-disabled={disabled}
597+
tabIndex={disabled ? undefined : 0}
617598
onClick={onClick}
618599
>
619600
<span className='slds-media__figure slds-listbox__option-icon'>

0 commit comments

Comments
 (0)