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

[Popper] Fix position when changing state or updated #18813

Merged
merged 2 commits into from
Dec 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 1 addition & 16 deletions docs/src/pages/components/slider/CustomizedSlider.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,8 @@ const useStyles = makeStyles(theme => ({
function ValueLabelComponent(props) {
const { children, open, value } = props;

const popperRef = React.useRef(null);
React.useEffect(() => {
if (popperRef.current) {
popperRef.current.update();
}
});

return (
<Tooltip
PopperProps={{
popperRef,
}}
open={open}
enterTouchDelay={0}
placement="top"
title={value}
>
<Tooltip open={open} enterTouchDelay={0} placement="top" title={value}>
{children}
</Tooltip>
);
Expand Down
18 changes: 1 addition & 17 deletions docs/src/pages/components/slider/CustomizedSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { withStyles, makeStyles, Theme, createStyles } from '@material-ui/core/s
import Slider from '@material-ui/core/Slider';
import Typography from '@material-ui/core/Typography';
import Tooltip from '@material-ui/core/Tooltip';
import PopperJs from 'popper.js';

const useStyles = makeStyles((theme: Theme) =>
createStyles({
Expand All @@ -25,23 +24,8 @@ interface Props {
function ValueLabelComponent(props: Props) {
const { children, open, value } = props;

const popperRef = React.useRef<PopperJs | null>(null);
React.useEffect(() => {
if (popperRef.current) {
popperRef.current.update();
}
});

return (
<Tooltip
PopperProps={{
popperRef,
}}
open={open}
enterTouchDelay={0}
placement="top"
title={value}
>
<Tooltip open={open} enterTouchDelay={0} placement="top" title={value}>
{children}
</Tooltip>
);
Expand Down
7 changes: 1 addition & 6 deletions packages/material-ui-lab/src/Autocomplete/Autocomplete.d.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import * as React from 'react';
import { StandardProps } from '@material-ui/core';
import { PopperProps } from '@material-ui/core/Popper';
import { UseAutocompleteProps, CreateFilterOptions, createFilterOptions } from '../useAutocomplete';

export { createFilterOptions };

export interface PopperProps extends React.HTMLAttributes<HTMLElement> {
anchorEl?: HTMLElement;
open: boolean;
popperRef: React.Ref<unknown>;
}

export interface RenderOptionState {
inputValue: string;
selected: boolean;
Expand Down
9 changes: 1 addition & 8 deletions packages/material-ui-lab/src/Autocomplete/Autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export const styles = theme => ({

function DisablePortal(props) {
// eslint-disable-next-line react/prop-types
const { popperRef, anchorEl, open, ...other } = props;
const { anchorEl, open, ...other } = props;
return <div {...other} />;
}

Expand Down Expand Up @@ -267,12 +267,6 @@ const Autocomplete = React.forwardRef(function Autocomplete(props, ref) {
} = props;
/* eslint-enable no-unused-vars */

const popperRef = React.useRef(null);
React.useEffect(() => {
if (popperRef.current) {
popperRef.current.update();
}
});
const PopperComponent = disablePortal ? DisablePortal : PopperComponentProp;

const {
Expand Down Expand Up @@ -412,7 +406,6 @@ const Autocomplete = React.forwardRef(function Autocomplete(props, ref) {
width: anchorEl ? anchorEl.clientWidth : null,
}}
role="presentation"
popperRef={popperRef}
anchorEl={anchorEl}
open
>
Expand Down
6 changes: 6 additions & 0 deletions packages/material-ui/src/Popper/Popper.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ const Popper = React.forwardRef(function Popper(props, ref) {
*/
const [placement, setPlacement] = React.useState(rtlPlacement);

React.useEffect(() => {
if (popperRef.current) {
popperRef.current.update();
}
});

const handleOpen = React.useCallback(() => {
if (!tooltipRef.current || !anchorEl || !open) {
return;
Expand Down