add prop for Layout with Sider
See original GitHub issueRight now we have to use like this:
<Layout>
<Layout.Sider>...</Layout.Sider>
</Layout>
in that case we have classname ant-layout-has-sider
But if we have custom Sider like this:
const Sider = (props) => <Layout.Sider>.....</Layout.Sider>
<Layout>
<Sider>...</Sider>
</Layout>
in that case we don’t have classname ant-layout-has-sider, because you are checking for property name:
ele && ele.props && ele.props.name === 'Sider'
so we can fix it by 2 ways now:
-
manually add classname ant-layout-has-sider to Layout, but I would consider it like internal feature, this classname can be changed in future
-
manually add property name to our custom Side, but I would consider it like internal feature too, you can change that logic in future.
As possible fix I would recommend next fix add property withSider to Layout:
Layout.propTypes = {
withSider: PropTypes.bool
}
and check it like this:
const { prefixCls, className, children, name, ...others } = this.props;
let hasSider = this.props.hasSider;
if (name === 'Layout') {
React.Children.forEach(children, (ele: React.ReactElement<any>) => {
if (ele && ele.props && ele.props.name === 'Sider') {
hasSider = true;
}
});
}
and use it like this:
const Sider = (props) => <Layout.Sider>.....</Layout.Sider>
<Layout withSider>
<Sider>...</Sider>
</Layout>
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Adding Props to Sidebar Component - YouTube
Adding props to sidebar component.Code: https://github.com/benawad/slack-clone-client/tree/10_add_props_to_components----Video ...
Read more >Layout
Layout : The layout wrapper, in which Header Sider Content Footer or Layout itself can be nested, and can be placed in any...
Read more >antd.Layout.Sider JavaScript and Node.js code examples
Best JavaScript code snippets using antd.Layout.Sider(Showing top 2 results out of 315) · src/components/layout/Sider.jsx/Sider/render · src/containers/sidebar.js ...
Read more >Creating a Responsive Sidebar in Ant Design
The Sidebar takes in a menu prop, which contains the menu to display the contents with. Since the NavBar also needs the same...
Read more >Building a React Sidebar Menu Navigation Component with ...
Adding routing functionality to the sidebar ... a "section" or "bar" on the side of the page that typically holds navigation links to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
well, right now I’m using it like this (pass name prop manually):
This thread has been automatically locked because it has not had recent activity. Please open a new issue for related bugs and link to relevant comments in this thread.