Skip to content

Commit

Permalink
Fixes to EuiAccordion adjust exposed height (#3160)
Browse files Browse the repository at this point in the history
* Changed EuiMutationObserver to EuiResizeObserver

Currently working in supported browers

* Changed EuiMutationObserver to EuiResizeObserver

Currently working in supported browers

* Logged in CHANGELOG.md

* Removed/modified dependencies

* Modified yarn.lock file

Co-authored-by: Greg Thompson <thompson.glowe@gmail.com>
  • Loading branch information
winnllam and thompsongl committed Mar 31, 2020
1 parent 31c332b commit 93effed
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 51 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
- Added `title` and `aria` attributes to `EuiToken`'s icon element ([#3195](https://github.com/elastic/eui/pull/3195))
- Added new Elasticsearch token types ([58036](https://github.com/elastic/kibana/issues/58036))

**Bug Fixes**

- Fixed bug in `EuiAccordion` to adjust to the correct height when content height changes ([#3160](https://github.com/elastic/eui/pull/3160))

## [`22.2.0`](https://github.com/elastic/eui/tree/v22.2.0)

- Improved `EuiModal` close button position to prevent from overlapping with the title ([#3176](https://github.com/elastic/eui/pull/3176))
Expand Down
30 changes: 6 additions & 24 deletions src/components/accordion/__snapshots__/accordion.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,15 @@ exports[`EuiAccordion behavior closes when clicked twice 1`] = `
className="euiAccordion__childWrapper"
id="8"
>
<EuiMutationObserver
observerOptions={
Object {
"attributeFilter": Array [
"style",
],
"childList": true,
"subtree": true,
}
}
onMutation={[Function]}
<EuiResizeObserver
onResize={[Function]}
>
<div>
<div
className=""
/>
</div>
</EuiMutationObserver>
</EuiResizeObserver>
</div>
</div>
</EuiAccordion>
Expand Down Expand Up @@ -111,24 +102,15 @@ exports[`EuiAccordion behavior opens when clicked once 1`] = `
className="euiAccordion__childWrapper"
id="7"
>
<EuiMutationObserver
observerOptions={
Object {
"attributeFilter": Array [
"style",
],
"childList": true,
"subtree": true,
}
}
onMutation={[Function]}
<EuiResizeObserver
onResize={[Function]}
>
<div>
<div
className=""
/>
</div>
</EuiMutationObserver>
</EuiResizeObserver>
</div>
</div>
</EuiAccordion>
Expand Down
32 changes: 5 additions & 27 deletions src/components/accordion/accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import classNames from 'classnames';
import { CommonProps, keysOf } from '../common';

import { EuiIcon } from '../icon';
import { EuiMutationObserver } from '../observer/mutation_observer';
import { getDurationAndPerformOnFrame } from '../../services';

const MUTATION_ATTRIBUTE_FILTER = ['style'];
import { EuiResizeObserver } from '../observer/resize_observer';

const paddingSizeToClassNameMap = {
none: '',
Expand Down Expand Up @@ -87,19 +84,6 @@ export class EuiAccordion extends Component<
});
};

onMutation = (records: MutationRecord[]) => {
const isChildStyleMutation = records.find((record: MutationRecord) => {
return record.attributeName
? MUTATION_ATTRIBUTE_FILTER.indexOf(record.attributeName) > -1
: false;
});
if (isChildStyleMutation) {
getDurationAndPerformOnFrame(records, this.setChildContentHeight);
} else {
this.setChildContentHeight();
}
};

componentDidMount() {
this.setChildContentHeight();
}
Expand Down Expand Up @@ -207,23 +191,17 @@ export class EuiAccordion extends Component<
this.childWrapper = node;
}}
id={id}>
<EuiMutationObserver
observerOptions={{
childList: true,
subtree: true,
attributeFilter: MUTATION_ATTRIBUTE_FILTER,
}}
onMutation={this.onMutation}>
{mutationRef => (
<EuiResizeObserver onResize={this.setChildContentHeight}>
{resizeRef => (
<div
ref={ref => {
this.setChildContentRef(ref);
mutationRef(ref);
resizeRef(ref);
}}>
<div className={paddingClass}>{children}</div>
</div>
)}
</EuiMutationObserver>
</EuiResizeObserver>
</div>
</div>
);
Expand Down

0 comments on commit 93effed

Please sign in to comment.