Skip to content

Commit

Permalink
use context
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Nov 16, 2019
1 parent 46e98b3 commit f8a9511
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions packages/material-ui/src/Popper/Popper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@ import React from 'react';
import PropTypes from 'prop-types';
import PopperJS from 'popper.js';
import { chainPropTypes, refType } from '@material-ui/utils';
import { useTheme } from '@material-ui/styles';
import Portal from '../Portal';
import createChainedFunction from '../utils/createChainedFunction';
import setRef from '../utils/setRef';
import useForkRef from '../utils/useForkRef';
import ownerWindow from '../utils/ownerWindow';

/**
* Flips placement if in <body dir="rtl" />
* @param {string} placement
*/
function flipPlacement(placement) {
const direction = (typeof document !== 'undefined' && document.body.getAttribute('dir')) || 'ltr';
function flipPlacement(placement, theme) {
const direction = theme.direction || 'ltr';

if (direction !== 'rtl') {
if (direction === 'ltr') {
return placement;
}

Expand Down Expand Up @@ -72,7 +69,8 @@ const Popper = React.forwardRef(function Popper(props, ref) {

const [exited, setExited] = React.useState(true);

const rtlPlacement = flipPlacement(initialPlacement);
const theme = useTheme();
const rtlPlacement = flipPlacement(initialPlacement, theme);
/**
* placement initialized from prop but can change during lifetime if modifiers.flip.
* modifiers.flip is essentially a flip for controlled/uncontrolled behavior
Expand Down

0 comments on commit f8a9511

Please sign in to comment.