primefaces / primereact

The Most Complete React UI Component Library
https://primereact.org
MIT License
6.68k stars 1.01k forks source link

MultiSelect: Causes horizontal scroll to align with multiselect option panel when opening panel when an item is selected #2855

Closed sleepybjr closed 2 years ago

sleepybjr commented 2 years ago

Describe the bug

When using horizontal scrolling on a page, opening the multiselect panel causes your app to scroll to the right to the start of the panel.

The line that makes this occur is: https://github.com/primefaces/primereact/blob/7cb4bc1327ce4ff71cc1943c205fa5a2f8613020/components/lib/multiselect/MultiSelect.js#L218

Changing inline option to nearest would not cause a scroll on the horizontal axis when opening the panel. Unless there is a reason why it uses start that I am unsure about. highlightItem.scrollIntoView({ block: 'nearest', inline: nearest' });

Reproducer

No response

PrimeReact version

8.0.1

React version

18.x

Language

ALL

Build / Runtime

Next.js

Browser(s)

No response

Steps to reproduce the behavior

  1. Allow overflow-x on your web app.
  2. Overflow it so horizontal scroll bar is shown.
  3. Open MultiSelect dropdown and select an item.
  4. Close and reopen MultiSelect dropdown.
  5. Observe that the entire page shifts to the right to align with the left of the MultiSelect panel.

Expected behavior

Page should not shift horizontally unless the panel is out of view.

melloware commented 2 years ago

Excellent report. I will take a look