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 global filters position on window resize #14

Merged
Merged
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
45 changes: 21 additions & 24 deletions src-docs/src/views/header/global_query.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import React, { Component } from 'react';
import classNames from 'classnames';

import ResizeObserver from 'resize-observer-polyfill';
import {
EuiFilterButton,
EuiFieldText,
EuiFlexGroup,
EuiFlexItem,
EuiMutationObserver,
} from '../../../../src/components';

import { GlobalFilterBar } from './global_filter_bar';
Expand Down Expand Up @@ -58,6 +57,8 @@ export default class extends Component {
],
query: '',
};

this.ro = new ResizeObserver(this.setFilterBarHeight);
}

setFilterBarHeight = () => {
Expand All @@ -69,10 +70,12 @@ export default class extends Component {

componentDidMount() {
this.setFilterBarHeight();
this.ro.observe(this.filterBar);
}

componentDidUpdate() {
this.setFilterBarHeight();
this.ro.unobserve(this.filterBar);
}

toggleFilterVisibility = () => {
Expand Down Expand Up @@ -132,28 +135,22 @@ export default class extends Component {
ref={node => { this.filterBarWrapper = node; }}
className={classes}
>
<EuiMutationObserver
observerOptions={{ childList: true, subtree: true }}
onMutation={this.setFilterBarHeight}
>
<div ref={this.setFilterBarRef}>
<EuiFlexGroup
className="globalFilterGroup"
gutterSize="none"
alignItems="flexStart"
responsive={false}
>
<EuiFlexItem className="globalFilterGroup__branch" grow={false}>
<GlobalFilterOptions />
</EuiFlexItem>

<EuiFlexItem>
<GlobalFilterBar className="globalFilterGroup__filterBar" filters={this.state.filters} />
</EuiFlexItem>
</EuiFlexGroup>
</div>

</EuiMutationObserver>
<div ref={this.setFilterBarRef}>
<EuiFlexGroup
className="globalFilterGroup"
gutterSize="none"
alignItems="flexStart"
responsive={false}
>
<EuiFlexItem className="globalFilterGroup__branch" grow={false}>
<GlobalFilterOptions />
</EuiFlexItem>

<EuiFlexItem>
<GlobalFilterBar className="globalFilterGroup__filterBar" filters={this.state.filters} />
</EuiFlexItem>
</EuiFlexGroup>
</div>
</div>

</React.Fragment>
Expand Down