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

[Menu] [Popover] Fix anchoring on active item scroll into view #7346

Closed
wants to merge 1 commit into from

Conversation

quiaro
Copy link
Contributor

@quiaro quiaro commented Jul 5, 2017

Fix Menu not anchored correctly if active item is deep in the scroll view

  • PR has tests / docs demo, and is linted.
  • Commit and PR titles begin with [ComponentName], and are in imperative form: "[Component] Fix leaky abstraction".
  • Description explains the issue / use-case resolved, and auto-closes the related issue(s) (http://tr.im/vFqem).

Popover was calculating the anchor offset via getContentAnchorOffset using the index of the menu's selected item, but this made the calculation unreliable once the height of the menu list exceeded the Popover's height (i.e. clientHeight). I moved getContentAnchorOffset to Menu instead, where it's possible to know the height of the list as well.

getContentAnchorOffset calculates the anchor offset for the popover while ensuring that the menu's selected item stays anchored to the anchor element. To reduce as much as possible the need to adjust the popover's position based on the selected item, getContentAnchorOffset scrolls the selected item into view with the goal of keeping the popover centered vertically over the anchor element.

I'm very excited to make my first contribution to this great project. Big props to the maintainers :)

@stunaz
Copy link
Contributor

stunaz commented Jul 5, 2017

does this fix #5937?

@quiaro
Copy link
Contributor Author

quiaro commented Jul 6, 2017

No, it would be a separate fix for #5937.

@arracso
Copy link

arracso commented Jul 6, 2017

Hi, I'm new using Material-UI and npm.
I'm having this bug. Will this fix be applied to npm package early?

…ep in the scroll view

Fix flow errors

Test method returning positioning styles; remove redundant tests
@quiaro
Copy link
Contributor Author

quiaro commented Jul 6, 2017

@oliviertassinari After rebasing, argos now reports a lot of regression tests failing. Looks like there are some style changes, though I did not change any styles. Is there anything I should do or is this a problem with argos failing to load some of the styles? Earlier today before the rebase, all tests were passing 😕

@oliviertassinari
Copy link
Member

I have started a new build.

@rosskevin rosskevin changed the title [Menu] [Popover] Fix Menu not anchored correctly if active item is de… [Menu] [Popover] Fix anchoring on active item scroll into view Jul 7, 2017
@oliviertassinari
Copy link
Member

It's green, I'm looking into the issue now.

@oliviertassinari
Copy link
Member

I found the corresponding issue #6731
capture d ecran 2017-07-07 a 23 00 35

@oliviertassinari
Copy link
Member

oliviertassinari commented Jul 7, 2017

I was able to get a rough fix with the following changes. Looking into that solution now.

+++ b/src/internal/Popover.js
@@ -4,6 +4,7 @@ import React, { Component } from 'react';
 import type { Element } from 'react';
 import classNames from 'classnames';
 import { createStyleSheet } from 'jss-theme-reactor';
+import Style from 'fbjs/lib/Style';
 import contains from 'dom-helpers/query/contains';
 import withStyles from '../styles/withStyles';
 import customPropTypes from '../utils/customPropTypes';
@@ -355,7 +356,10 @@ class Popover extends Component<DefaultProps, Props, void> {
     if (this.props.getContentAnchorEl) {
       const contentAnchorEl = this.props.getContentAnchorEl(element);
       if (contentAnchorEl && contains(element, contentAnchorEl)) {
-        contentAnchorOffset = contentAnchorEl.offsetTop + contentAnchorEl.clientHeight / 2 || 0;
+        contentAnchorOffset =
+          contentAnchorEl.offsetTop +
+            contentAnchorEl.clientHeight / 2 -
+            Style.getScrollParent(contentAnchorEl).parentNode.scrollTop || 0;
       }
     }

@oliviertassinari
Copy link
Member

oliviertassinari commented Jul 7, 2017

by rough, I mean that "my" solution have this limitation, but I have seen the same one with that PR, so I don't follow. What's the extra complexity is for?

bug

@oliviertassinari
Copy link
Member

@quiaro Thanks for working on that issue, it's higly appreciated 👍

@oliviertassinari oliviertassinari added the waiting for 👍 Waiting for upvotes label Jul 7, 2017
@oliviertassinari
Copy link
Member

I have applied the proposed logic in the issue, thanks for your time!

@oliviertassinari
Copy link
Member

oliviertassinari commented Jul 9, 2017

Let us know if we still have issues to fix.

@oliviertassinari oliviertassinari removed the waiting for 👍 Waiting for upvotes label Oct 2, 2017
@zannager zannager added the component: menu This is the name of the generic UI component, not the React module! label Mar 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: menu This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants