Skip to content
This repository has been archived by the owner on May 20, 2021. It is now read-only.

Accordion component breaks when list of items changes #63

Open
zion opened this issue Apr 12, 2017 · 7 comments
Open

Accordion component breaks when list of items changes #63

zion opened this issue Apr 12, 2017 · 7 comments

Comments

@zion
Copy link

zion commented Apr 12, 2017

Im having an issue with a list of items returned from the server after a passed in search string. As the search keyword changes the, accordion items change to properly reflect the matching results, however after the accordion <li>s change they no longer open/close.

Is there a way to re-initiate foundation on the accordion object after the contents change?

@donaldwasserman
Copy link
Contributor

Can you provide a little code to see how you're doing this?

@zion
Copy link
Author

zion commented Apr 17, 2017

Figured out how to address it by adding this to the component for the <li> elements in the accordion. Although JShint says Foundation is not defined. oh well...

// component.js

didInsertElement(){
    new Foundation.Accordion(this.$().parent(), { multiExpand: true, allowAllClosed: true});
  },```

@obernal
Copy link
Contributor

obernal commented Jun 14, 2017

@donaldwasserman I had the same problem while working with zf-accordion and adding elements to it after the first render. The problem has to do with didInsertElement being called only on the initial render as per the docs https://guides.emberjs.com/v2.13.0/components/the-component-lifecycle/. I was able to resolve this by changing didInsertElement on the zf-widget mixin to willRender. After that, everything worked well. That might not be the best place to put it or the best way to deal with the problem. I basically just looked for a hook that was called on every render and tested to see if it worked :). Let me know if you need a PR and I'll submit it.

@GCheung55
Copy link
Collaborator

I haven't looked into this too deeply but at first glance it sounds like didReceiveAttrs or an observer would be better suited.

@zion
Copy link
Author

zion commented Jun 15, 2017

@obernal Did you override the mixin then?

@obernal
Copy link
Contributor

obernal commented Jun 15, 2017

@zion yes. My items are not components and I think it should be the accordion's responsibility to accept new items anyway so that's why this would require changes to the actual code. @GCheung55 didReceiveAttrs is called on re-render as well but I believe is called if the component's attributes change only. We are not changing attributes, but adding list items so I'm not sure it'll work. I will try it, but is there a reason willRender is not a good place for it? I haven't worked with ember much and I'm not 100% familiar with the code the mixin is executing so I'm mostly just curious.

@zion
Copy link
Author

zion commented Jun 15, 2017

Ok, I seem to have broken all of my accordions by updating to ember-cli 2.13.2 and foundation 6.3.1

I might try your solution to see if that helps

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants