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

add MutationObserver to accordion to trigger setChildContentHeight when children change #947

Merged
merged 4 commits into from
Jun 27, 2018

Conversation

nreese
Copy link
Contributor

@nreese nreese commented Jun 26, 2018

EuiAccordion does not update height when children internal state changes. I updated the AccordionGrow example to demonstrate. When the counter is modified inside the sub-component than EuiAccordion's componentDidUpdate never gets called because none of the props passed to children changed.

This PR adds a MutationObserver to update height any time the children DOM tree changes.

Copy link
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

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

Works for me in Chrome and IE.

@@ -44,6 +44,15 @@ export class EuiAccordion extends Component {

componentDidMount() {
this.setChildContentHeight();

requestAnimationFrame(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you test this without requestAnimationFrame? I don't think it needs the delay.

@@ -44,6 +44,13 @@ export class EuiAccordion extends Component {

componentDidMount() {
this.setChildContentHeight();

this.observer = new MutationObserver(this.setChildContentHeight);
this.observer.observe(this.childContent, { childList: true, subtree: true });
Copy link
Contributor

Choose a reason for hiding this comment

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

Last thing, sorry for not catching this before.

If this.childContent changes to a new ref before componentWillUnmount is called the new content isn't tracked. This observer creation should be moved to where this.childContent is set (currently an inline arrow function, that will need to be promoted to a method on the component class). The ref setting function should check if the incoming ref is null or not; if this.observer exists, disconnect; then if ref is not null, create new observer.

The setRef method will be called with null on unmount, so there is no need to keep componentWIllUnmount

Copy link
Contributor

@chandlerprall chandlerprall left a comment

Choose a reason for hiding this comment

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

LGTM; pulled & tested example which works as expected

@snide
Copy link
Contributor

snide commented Jun 26, 2018

jenkins, test this

@nreese nreese merged commit c64f055 into elastic:master Jun 27, 2018
cchaos pushed a commit to cchaos/eui that referenced this pull request Jun 28, 2018
commit 2eea143
Author: cchaos <caroline.horn@elastic.co>
Date:   Thu Jun 28 12:56:56 2018 -0400

    Get rid of terrible IE highlight when select is focused

commit 66647f0
Author: cchaos <caroline.horn@elastic.co>
Date:   Thu Jun 28 12:07:54 2018 -0400

    Revert commit of filter_button.scss

commit c2e8a73
Author: cchaos <caroline.horn@elastic.co>
Date:   Thu Jun 28 12:00:54 2018 -0400

    Simplifying form control styles

    - Made bottom colored border from linear-gradient
    - Allowing parameters to determine if just the borders should render
    - Allowing parameters to determine if all state styles should be added
    - Fixing variable naming schemes

commit c5f0ab5
Author: Stacey Gammon <gammon@elastic.co>
Date:   Thu Jun 28 10:02:16 2018 -0400

    add inspect to typedef file (elastic#952)

    * add inpsect to typedef file

    * use the right pr number

commit c64f055
Author: Nathan Reese <reese.nathan@gmail.com>
Date:   Wed Jun 27 08:52:41 2018 -0600

    add MutationObserver to accordion to trigger setChildContentHeight when children change (elastic#947)

    * add MutationObserver to accordion to trigger setChildContentHeight when children change

    * remove requestAnimationFrame around MutationObserver registration and add comment to change log

    * set up observer in ref creation function

    * mock MutationObserver
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants