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

[Tabs] wrapping tabs in custom function breaks onChange #13893

Closed
2 tasks done
el1f opened this issue Dec 13, 2018 · 4 comments
Closed
2 tasks done

[Tabs] wrapping tabs in custom function breaks onChange #13893

el1f opened this issue Dec 13, 2018 · 4 comments

Comments

@el1f
Copy link
Contributor

el1f commented Dec 13, 2018

  • This is not a v0.x issue.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior 🤔

When using a Tabs components with a custom child which renders a Tab component as it's only child it should work as if I'm writing the tabs as direct children of the Tabs component.

Current Behavior 😯

onChange and active don't seem to propagate to the tabs rendered by the custom component. Is this the intended behaviour? Can I pass the props to my custom component somehow?

Steps to Reproduce 🕹

Link: https://codesandbox.io/s/l2762q1kwl

  1. replace TabItem with a Tab and give it the tab prop instead of the label prop
  2. tabs are now functional

Context 🔦

I'm trying to get my Tabs in wrappers to avoid repetition to the best of my ability and I'm trying to understand why this is the case with tabs

Your Environment 🌎

Tech Version
Material-UI v3.2.2
React v16.5.2
Browser chrome
@eps1lon
Copy link
Member

eps1lon commented Dec 13, 2018

We should add this limitation to the docs. It's the same issue that's causing troubles with wrapped Tooltips around Tabs.

Basically a Tab has to be the immediate child of Tabs right now. Otherwise certain features cannot function properly.

A workaround for now is to use a render function instead of a component.

@eps1lon eps1lon added new feature New feature or request docs Improvements or additions to the documentation labels Dec 13, 2018
@oliviertassinari
Copy link
Member

oliviertassinari commented Dec 16, 2018

A workaround for now is to use a render function instead of a component.

It's simpler than that: they can just forward the properties, it's a 1-2 lines change.

We should add this limitation to the docs.

We try to cover this part in https://material-ui.com/guides/composition/. I doubt we can do more about it, any idea?

Hum, maybe we could enforce the usage of .muiName. This way, we can raise a warning and educate our users with a link to this documentation page? I think that a large part of the issue comes from the frustration it creates.

Related to #12921.

@oliviertassinari oliviertassinari added discussion and removed docs Improvements or additions to the documentation new feature New feature or request labels Dec 16, 2018
@el1f
Copy link
Contributor Author

el1f commented Dec 17, 2018

Oh, I just need to compose the props? Sorry guys, never seen that page of the docs :/

@oliviertassinari
Copy link
Member

oliviertassinari commented Dec 17, 2018

@el1f Yes, you can solve the problem like this:

-   const TabItem = ({ label }) => (
+   const TabItem = ({ label, ...props }) => (
      <Tab
        classes={{
          root: "Tabs-layout__tabs__item",
          labelContainer: "Tabs-layout__tabs__label"
        }}
        label={<TabLabel>{label}</TabLabel>}
        disableRipple
+       {...props}
      />
    );

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

No branches or pull requests

3 participants