question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Options menu appear outside the viewport for some layouts

See original GitHub issue

Default behaviour for when options menu goes beyond the visible area is scrolling down to show hidden part of options menu. Current version uses window.scrollBy to scroll and show menu.

However, it doesn’t always work. Sometimes you need to scroll particular parent in DOM hierarchy to make it actually scroll. Like in my case - I have sidebar div and a page div inside the flex row parent, in this case window.scrollBy will not work but scrolling page div does the trick.

Here is the Plunker of the problem: https://plnkr.co/edit/8FDDskB6qpoZWaNiaxvR?p=preview

Going to fix it by introducing new property of scrollable parent container id you want to scroll.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
aaronincincycommented, Jun 28, 2017

I’ve solved this problem temporarily by adding the below code to an onOpen handler, but I would greatly prefer not having to rely on internal implementation to make this work. Is there any plan to move this forward? Can my code be of any use?

onOpen = () => {
  window.requestAnimationFrame(() => {
    if (this.select.props.scrollMenuIntoView && this.select.menuContainer && this.select.menu) {
      const container = getScrollParent(this.select.menuContainer);
      const menuRect = this.select.menu.getBoundingClientRect();
      const containerRect = container.getBoundingClientRect();
      const scrollBottom = containerRect.top + containerRect.height;

      if (menuRect.bottom > scrollBottom) {
        container.scrollTop += menuRect.bottom - scrollBottom;
      }
    }
  })
}

The definition of getScrollParent is something I found on StackOverflow I think:

function getScrollParent(element, includeHidden) {
  var style = getComputedStyle(element);
  var excludeStaticParent = style.position === "absolute";
  var overflowRegex = includeHidden ? /(auto|scroll|hidden)/ : /(auto|scroll)/;

  if (style.position === "fixed") return document.body;
  for (var parent = element; (parent = parent.parentElement);) {
    style = getComputedStyle(parent);
    if (excludeStaticParent && style.position === "static") {
      continue;
    }
    if (overflowRegex.test(style.overflow + style.overflowY + style.overflowX)) return parent;
  }

  return document.body;
}

I would be ok passing this value in as a prop or having you auto-determine it, whichever you think is best

1reaction
luetkemjcommented, Jan 5, 2018

Any status updates on this issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Viewport concepts - CSS: Cascading Style Sheets | MDN
Your viewport is everything that is currently visible, notably, the "what is a viewport" section, and perhaps some of the navigation menu. The ......
Read more >
Fire event when menu is outside viewport and fix ...
Once the user scrolls past the header the menu should become fixed to the top of the browser viewport so that the menu...
Read more >
Viewport Layouts | 3ds Max 2020
Viewport Layouts gives you a special tab bar for switching quickly among any number of different viewport layouts.
Read more >
Menu subitems out of viewport
Hi, when using a horizontal full-width menu with a decent lot of items, having subitems and even sub-subitems, the ones more on the...
Read more >
AutoCAD Tutorial - Viewports: Layout - YouTube
Learn how to use the Layouts tab in AutoCAD to create custom scale, set layout scale, and lock the scale adjustment in your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found