Travix-International / travix-ui-kit

[DEPRECATED] Travix UI Components' repository.
https://travix-international.github.io/travix-ui-kit/
MIT License
8 stars 10 forks source link

Improve side panel implementation to get rid of data-rel #244

Open spzm opened 6 years ago

spzm commented 6 years ago

Description

this.closeButtons = [].slice.call(this.panel.querySelectorAll('[data-rel="close"]')); this.closeButtons.forEach(b => b.addEventListener('click', this.handleClose));

For now SlidePanel goes though all elements that have data-rel="close" in the children (through real dom) and add native click event listener for them. I see it as convenient solution to have close button in any place of SlidePanel. I propose to update the implementation just to more explicit way.

Steps to reproduce

We found several issues:

<SidePanel>
  <button data-rel="close" />
  <SidePanel>
    <button data-rel="close" />
  </SidePanel>
</SidePanel>

Proposal

I propose to try component as a function approach here to pass close handlers to the children. Please comment if you have better or alternative solutions!

<SlidePanel>
  {(close) => {
    return (
       ... some content
       <button onClick={close} />
       ... some content
    );
  }}
</SlidePanel>
asci commented 6 years ago

it could be implemented backward compatible

mAiNiNfEcTiOn commented 6 years ago

Interesting idea! If you don't have time for it I can pick it up, if you don't mind 😄