-
-
Notifications
You must be signed in to change notification settings - Fork 447
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
Added nested Tablist Support #180
Conversation
Much needed feature +1 |
Much needed feature indeed, and nested TabPanels are much needed as well. There's simply no reason for not being able to wrap a TabPanel in a div, for example. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR. As commented inline this will break nesting of react-tabs right now. Maybe you have an idea how to work around this?
@@ -132,7 +133,7 @@ export default class UncontrolledTabs extends Component { | |||
} | |||
|
|||
// Map children to dynamically setup refs | |||
return React.Children.map(children, child => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will not work when another react-tabs instance is nested inside I think, as it will find all children.
<Tabs>
<TabPanel>
<Tabs>
<TabPanel></TabPanel>
</Tabs>
</TabPanel>
</Tabs>
Not sure how to avoid this, as we also couldn't check if child === Tabs as children seem to be visited first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also the reason why the tests are failing.
@@ -157,7 +158,7 @@ export default class UncontrolledTabs extends Component { | |||
} | |||
|
|||
result = cloneElement(child, { | |||
children: React.Children.map(child.props.children, tab => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we use deepMap, we could actually remove the nested map here, as we would visit the Tab anyway in the outer map?
import TabList from '../components/TabList'; | ||
import Tab from '../components/Tab'; | ||
import TabPanel from '../components/TabPanel'; | ||
|
||
export function getTabsCount(children) { | ||
const tabLists = React.Children.toArray(children).filter(x => x.type === TabList); | ||
let tabList; | ||
Children.deepForEach(children, c => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use deepFind here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see your comment now in the inital message...hmm
error = new Error( | ||
`Expected 'TabList' or 'TabPanel' but found '${child.type.displayName || child.type}' in \`${componentName}\``, | ||
); | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes this could be removed then.
You can now nest TabList as per #114
ie.
Few things
Thoughts?