-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
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
Conversation
does this fix #5937? |
No, it would be a separate fix for #5937. |
Hi, I'm new using Material-UI and npm. |
…ep in the scroll view Fix flow errors Test method returning positioning styles; remove redundant tests
@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 😕 |
I have started a new build. |
It's green, I'm looking into the issue now. |
I found the corresponding issue #6731 |
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;
}
} |
@quiaro Thanks for working on that issue, it's higly appreciated 👍 |
I have applied the proposed logic in the issue, thanks for your time! |
Let us know if we still have issues to fix. |
Fix Menu not anchored correctly if active item is deep in the scroll view
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 movedgetContentAnchorOffset
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 :)