Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dropdown positioned wrong in case appending it to different scrollable parent #2356

Open
slavede opened this issue Mar 14, 2024 · 1 comment

Comments

@slavede
Copy link

slavede commented Mar 14, 2024

Describe the bug
When body is not scrollable (overflow hidden), I want to have attached ng-select to main content div (which has overflow:auto).
Now, when _updateYPosition is called it takes into account top like this:

this._dropdown.style.top = offsetTop + delta + "px";

It should take a scrollTop of the 'appendTo' element and add that as well

This way, on open sets it to wrong positiong regarding y axis

Reproducbile example
https://stackblitz.com/edit/stackblitz-starters-kyjvws

Expected behavior
It should take a scrollTop of the 'appendTo' element

Screenshots
image

Desktop (please complete the following information):

  • OS: Windows
  • Browser: Chrome
  • Version: 122.0.6261.112

Additional context
Add any other context about the problem here.

@slavede
Copy link
Author

slavede commented Mar 14, 2024

I've tried overriding it and it works fine then

  const select = dropdownPanel['_select'].getBoundingClientRect();
  const parent = dropdownPanel['_parent'].getBoundingClientRect();
  const delta = select.height;
  if (dropdownPanel['_currentPosition'] === 'top') {
    const offsetBottom = parent.bottom - select.bottom;
    const parentScroll = dropdownPanel['_parent'].scrollTop;

    dropdownPanel['_dropdown'].style.bottom = offsetBottom + delta - parentScroll + 'px';
    dropdownPanel['_dropdown'].style.top = 'auto';
  } else if (dropdownPanel['_currentPosition'] === 'bottom') {
    const offsetTop = select.top - parent.top;
    const parentScroll = dropdownPanel['_parent'].scrollTop;
    dropdownPanel['_dropdown'].style.top = offsetTop + delta + parentScroll + 'px';
    dropdownPanel['_dropdown'].style.bottom = 'auto';
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants