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

[Tooltip] Update react-popper #11862

Merged
merged 1 commit into from
Jun 14, 2018
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
2 changes: 1 addition & 1 deletion .size-limit.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = [
name: 'The size of all the modules of material-ui.',
webpack: true,
path: 'packages/material-ui/build/index.js',
limit: '95.0 KB',
limit: '96.3 KB',
},
{
name: 'The main bundle of the docs',
Expand Down
120 changes: 69 additions & 51 deletions docs/src/pages/demos/menus/MenuListComposition.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { Manager, Target, Popper } from 'react-popper';
import { Manager, Reference, Popper } from 'react-popper';
import Button from '@material-ui/core/Button';
import ClickAwayListener from '@material-ui/core/ClickAwayListener';
import Collapse from '@material-ui/core/Collapse';
Expand Down Expand Up @@ -55,72 +55,90 @@ class MenuListComposition extends React.Component {
</MenuList>
</Paper>
<Manager>
<Target>
<div
ref={node => {
this.target1 = node;
}}
>
<Button
aria-owns={open ? 'menu-list-grow' : null}
aria-haspopup="true"
onClick={this.handleToggle}
<Reference>
{({ ref }) => (
<div
ref={node => {
this.target1 = node;
}}
>
Toggle Menu Grow
</Button>
</div>
</Target>
<Button
buttonRef={ref}
aria-owns={open ? 'menu-list-grow' : null}
aria-haspopup="true"
onClick={this.handleToggle}
>
Toggle Menu Grow
</Button>
</div>
)}
</Reference>
<Popper
placement="bottom-start"
eventsEnabled={open}
className={classNames({ [classes.popperClose]: !open })}
>
<ClickAwayListener onClickAway={this.handleClose}>
<Grow in={open} id="menu-list-grow" style={{ transformOrigin: '0 0 0' }}>
<Paper>
<MenuList role="menu">
<MenuItem onClick={this.handleClose}>Profile</MenuItem>
<MenuItem onClick={this.handleClose}>My account</MenuItem>
<MenuItem onClick={this.handleClose}>Logout</MenuItem>
</MenuList>
</Paper>
</Grow>
</ClickAwayListener>
{({ ref, style }) => (
<div ref={ref} style={style}>
<ClickAwayListener onClickAway={this.handleClose}>
<Grow in={open} id="menu-list-grow" style={{ transformOrigin: '0 0 0' }}>
<Paper>
<MenuList role="menu">
<MenuItem onClick={this.handleClose}>Profile</MenuItem>
<MenuItem onClick={this.handleClose}>My account</MenuItem>
<MenuItem onClick={this.handleClose}>Logout</MenuItem>
</MenuList>
</Paper>
</Grow>
</ClickAwayListener>
</div>
)}
</Popper>
</Manager>
<Manager>
<Target>
<div
ref={node => {
this.target2 = node;
}}
>
<Button
aria-owns={open ? 'menu-list-collapse' : null}
aria-haspopup="true"
onClick={this.handleToggle}
<Reference>
{({ ref }) => (
<div
ref={node => {
this.target2 = node;
}}
>
Toggle Menu Collapse
</Button>
</div>
</Target>
<Button
buttonRef={ref}
aria-owns={open ? 'menu-list-collapse' : null}
aria-haspopup="true"
onClick={this.handleToggle}
>
Toggle Menu Collapse
</Button>
</div>
)}
</Reference>
<Portal>
<Popper
placement="bottom"
eventsEnabled={open}
className={classNames({ [classes.popperClose]: !open })}
>
<ClickAwayListener onClickAway={this.handleClose}>
<Collapse in={open} id="menu-list-collapse" style={{ transformOrigin: '0 0 0' }}>
<Paper style={{ margin: 3 }}>
<MenuList role="menu">
<MenuItem onClick={this.handleClose}>Profile</MenuItem>
<MenuItem onClick={this.handleClose}>My account</MenuItem>
<MenuItem onClick={this.handleClose}>Logout</MenuItem>
</MenuList>
</Paper>
</Collapse>
</ClickAwayListener>
{({ ref, style }) => (
<div ref={ref} style={style}>
<ClickAwayListener onClickAway={this.handleClose}>
<Collapse
in={open}
id="menu-list-collapse"
style={{ transformOrigin: '0 0 0' }}
>
<Paper style={{ margin: 3 }}>
<MenuList role="menu">
<MenuItem onClick={this.handleClose}>Profile</MenuItem>
<MenuItem onClick={this.handleClose}>My account</MenuItem>
<MenuItem onClick={this.handleClose}>Logout</MenuItem>
</MenuList>
</Paper>
</Collapse>
</ClickAwayListener>
</div>
)}
</Popper>
</Portal>
</Manager>
Expand Down
50 changes: 29 additions & 21 deletions docs/src/pages/utils/popovers/MouseOverPopover.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Typography from '@material-ui/core/Typography';
import { withStyles } from '@material-ui/core/styles';
import Grow from '@material-ui/core/Grow';
import Paper from '@material-ui/core/Paper';
import { Manager, Target, Popper } from 'react-popper';
import { Manager, Reference, Popper } from 'react-popper';

const styles = theme => ({
paper: {
Expand Down Expand Up @@ -74,31 +74,39 @@ class MouseOverPopover extends React.Component {
<Typography>I use Popover.</Typography>
</Popover>
<Manager>
<Target>
<Typography
aria-describedby="react-popper-tooltip"
onMouseOver={this.handlePopperOpen}
onMouseOut={this.handlePopperClose}
>
Hover with react-popper.
</Typography>
</Target>
<Reference>
{({ ref }) => (
<div ref={ref}>
<Typography
aria-describedby="react-popper-tooltip"
onMouseOver={this.handlePopperOpen}
onMouseOut={this.handlePopperClose}
>
Hover with react-popper.
</Typography>
</div>
)}
</Reference>
<Popper
placement="bottom-start"
eventsEnabled={popperOpen}
className={!popperOpen ? classes.popperClose : ''}
>
<Grow in={popperOpen} style={{ transformOrigin: '0 0 0' }}>
<Paper
id="react-popper-tooltip"
className={classes.paper}
role="tooltip"
aria-hidden={!popperOpen}
elevation={8}
>
<Typography>I use react-popper.</Typography>
</Paper>
</Grow>
{({ ref, style }) => (
<div ref={ref} style={style}>
<Grow in={popperOpen} style={{ transformOrigin: '0 0 0' }}>
<Paper
id="react-popper-tooltip"
className={classes.paper}
role="tooltip"
aria-hidden={!popperOpen}
elevation={8}
>
<Typography>I use react-popper.</Typography>
</Paper>
</Grow>
</div>
)}
</Popper>
</Manager>
</div>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"doctrine": "^2.0.0",
"downshift": "^1.22.1",
"enzyme": "^3.2.0",
"enzyme-adapter-react-16": "^1.1.0",
"enzyme-adapter-react-16": "npm:enzyme-react-adapter-future",
"eslint": "^4.11.0",
"eslint-config-airbnb": "^16.1.0",
"eslint-import-resolver-webpack": "^0.10.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/material-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@
"prop-types": "^15.6.0",
"react-event-listener": "^0.6.0",
"react-jss": "^8.1.0",
"react-popper": "^0.10.0",
"react-popper": "^1.0.0",
"react-transition-group": "^2.2.1",
"recompose": "^0.26.0 || ^0.27.0",
"recompose": "^0.27.0",
"scroll": "^2.0.3",
"warning": "^4.0.1"
},
Expand Down
6 changes: 1 addition & 5 deletions packages/material-ui/src/Tooltip/Tooltip.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { IPopperProps } from 'react-popper';
import { PopperProps } from 'react-popper';
import { StandardProps } from '..';

export interface TooltipProps
Expand Down Expand Up @@ -43,10 +43,6 @@ export type TooltipClassKey =
| 'tooltipPlacementTop'
| 'tooltipPlacementBottom';

interface PopperProps extends IPopperProps {
PopperClassName: string;
}

declare const Tooltip: React.ComponentType<TooltipProps>;

export default Tooltip;
42 changes: 22 additions & 20 deletions packages/material-ui/src/Tooltip/Tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import EventListener from 'react-event-listener';
import debounce from 'debounce';
import warning from 'warning';
import classNames from 'classnames';
import { Manager, Popper, Target } from 'react-popper';
import { Manager, Popper, Reference } from 'react-popper';
import { capitalize } from '../utils/helpers';
import RootRef from '../RootRef';
import Portal from '../Portal';
Expand Down Expand Up @@ -137,13 +137,13 @@ class Tooltip extends React.Component {
touchTimer = null;
closeTimer = null;
isControlled = null;
popper = null;
scheduleUpdate = null;
children = null;
ignoreNonTouchEvents = false;

handleResize = debounce(() => {
if (this.popper) {
this.popper._popper.scheduleUpdate();
if (this.scheduleUpdate) {
this.scheduleUpdate();
}
}, 166); // Corresponds to 10 frames at 60 Hz.

Expand Down Expand Up @@ -314,41 +314,39 @@ class Tooltip extends React.Component {
);

return (
<Manager tag={false} {...other}>
<Manager {...other}>
<EventListener target="window" onResize={this.handleResize} />
<Target>
{({ targetProps }) => (
<Reference>
{({ ref }) => (
<RootRef
rootRef={node => {
this.children = node;
targetProps.ref(this.children);
ref(this.children);
}}
>
{React.cloneElement(children, childrenProps)}
</RootRef>
)}
</Target>
</Reference>
<Portal>
<Popper
placement={placement}
eventsEnabled={open}
className={classNames(classes.popper, { [classes.open]: open }, PopperClassName)}
ref={node => {
this.popper = node;
}}
{...PopperProps}
>
{({ popperProps, restProps }) => {
const actualPlacement = (popperProps['data-placement'] || placement).split('-')[0];
{popperProps => {
this.scheduleUpdate = popperProps.scheduleUpdate;
const actualPlacement = popperProps.placement
? popperProps.placement.split('-')[0]
: null;
return (
<div
{...popperProps}
{...restProps}
ref={popperProps.ref}
style={{
...popperProps.style,
top: popperProps.style.top || 0,
left: popperProps.style.left || 0,
...restProps.style,
}}
>
<div
Expand All @@ -357,9 +355,13 @@ class Tooltip extends React.Component {
aria-hidden={!open}
className={classNames(
classes.tooltip,
{ [classes.open]: open },
{ [classes.touch]: this.ignoreNonTouchEvents },
classes[`tooltipPlacement${capitalize(actualPlacement)}`],
{
[classes.open]: open,
[classes.touch]: this.ignoreNonTouchEvents,
},
popperProps.placement
? classes[`tooltipPlacement${capitalize(actualPlacement)}`]
: null,
)}
>
{title}
Expand Down
Loading