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

Fix bug where a position: fixed popover content doesn't scroll #1064

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
**Bug fixes**

- Fixed `EuiXYChart` responsive resize in a flexbox layout ([#1041](https://github.com/elastic/eui/pull/1041))
- Updated `EuiPopover` to reposition content when the window is scrolled. ([#1062](https://github.com/elastic/eui/pull/1062))

## [`3.2.1`](https://github.com/elastic/eui/tree/v3.2.1)

Expand Down
20 changes: 20 additions & 0 deletions src-docs/src/views/popover/popover_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ import PopoverContainer from './popover_container';
const popoverContainerSource = require('!!raw-loader!./popover_container');
const popoverContainerHtml = renderToHtml(PopoverContainer);

import PopoverFixed from './popover_fixed';
const popoverFixedSource = require('!!raw-loader!./popover_fixed');
const popoverFixedHtml = renderToHtml(PopoverFixed);

export const PopoverExample = {
title: 'Popover',
Expand Down Expand Up @@ -204,5 +207,22 @@ export const PopoverExample = {
</div>
),
demo: <PopoverHTMLElementAnchor />,
}, {
title: 'Popover on a static element',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on a fixed element

source: [{
type: GuideSectionTypes.JS,
code: popoverFixedSource,
}, {
type: GuideSectionTypes.HTML,
code: popoverFixedHtml,
}],
text: (
<div>
<p>
Popover content even works on <EuiCode>position: static;</EuiCode> elements.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed element.

</p>
</div>
),
demo: <PopoverFixed />,
}],
};
58 changes: 58 additions & 0 deletions src-docs/src/views/popover/popover_fixed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import React, {
Component,
} from 'react';

import {
EuiButton,
EuiPopover,
} from '../../../../src/components';

export default class PopoverContainer extends Component {
constructor(props) {
super(props);

this.state = {
isPopoverOpen: false,
};
}

onButtonClick = () => {
this.setState({
isPopoverOpen: !this.state.isPopoverOpen,
});
}

closePopover = () => {
this.setState({
isPopoverOpen: false,
});
}

setPanelRef = node => this.panel = node;

render() {
const button = (
<EuiButton
iconType="arrowDown"
iconSide="right"
onClick={this.onButtonClick}
style={{ background: 'white' }}
>
Show fixed popover
</EuiButton>
);

return (
<EuiPopover
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the docs I'd provide a separate button that says "Show fixed popover example", that then toggles the fixed button display so it isn't always shown.

This falls in line with how we handle other fixed content examples in the docs like modals, fixed progress bars, the bottom bar...etc.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably the best example of doing something like that.

button={button}
isOpen={this.state.isPopoverOpen}
closePopover={this.closePopover}
style={{ position: 'fixed', bottom: 50, right: 50 }}
>
<div>
This popover scrolls with the button element!
</div>
</EuiPopover>
);
}
}
3 changes: 3 additions & 0 deletions src/components/popover/popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ export class EuiPopover extends Component {
this.setState({ suppressingPopover: false, isOpening: true }); // eslint-disable-line react/no-did-mount-set-state
}

window.addEventListener('scroll', this.positionPopover);

this.updateFocus();
}

Expand Down Expand Up @@ -184,6 +186,7 @@ export class EuiPopover extends Component {
}

componentWillUnmount() {
window.removeEventListener('scroll', this.positionPopover);
clearTimeout(this.closingTransitionTimeout);
}

Expand Down