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

Dropdown & Popover fixes for dimensions and scrolling #608

Merged
merged 9 commits into from
Oct 1, 2019
6 changes: 3 additions & 3 deletions src/components/DropDown/DropDown.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ const DropDown = React.memo(function DropDown({

const [widthNoPx = MIN_WIDTH] = (width || '').split('px')
const [buttonWidth, setButtonWidth] = useState(0)
const [getContentWidth, setGetContentWidth] = useState(true)
const [measureWidth, setMeasureWidth] = useState(true)

// Adjust the button width if the item widths are larger than declared width
const [ghostElement, setGhostElement] = useState(null)
Expand All @@ -134,7 +134,7 @@ const DropDown = React.memo(function DropDown({
}, [ghostElement, widthNoPx])

useEffect(() => {
setGetContentWidth(true)
setMeasureWidth(true)
}, [vw, items])

// Update the button width every time the reference updates
Expand Down Expand Up @@ -223,7 +223,7 @@ const DropDown = React.memo(function DropDown({
`}
/>
</ButtonBase>
{getContentWidth && (
{measureWidth && (
<div
css={`
position: absolute;
Expand Down
12 changes: 10 additions & 2 deletions src/components/Popover/Popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,17 @@ class PopoverBase extends React.Component {
onClose()
}

boundaryDimensions() {
const { rootBoundary } = this.props
return rootBoundary
? [rootBoundary.clientWidth, rootBoundary.clientHeight]
: [window.innerWidth, window.innerHeight]
}

render() {
const { children, theme, transitionStyles, zIndex } = this.props
const { scale, opacity } = transitionStyles
const [maxWidth, maxHeight] = this.boundaryDimensions()
return (
<animated.div
css={`
Expand Down Expand Up @@ -193,8 +201,8 @@ class PopoverBase extends React.Component {
/* Having the popover visible already means that it focused. */
outline: 0;
}
max-height: calc(100vh - ${2 * GU}px);
max-width: calc(100vw - ${2 * GU}px);
max-height: calc(${maxHeight}px - ${2 * GU}px);
max-width: calc(${maxWidth}px - ${2 * GU}px);
AquiGorka marked this conversation as resolved.
Show resolved Hide resolved
overflow-y: auto;
`}
{...stylingProps(this)}
Expand Down