question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

add prop for Layout with Sider

See original GitHub issue

Right 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:

  1. manually add classname ant-layout-has-sider to Layout, but I would consider it like internal feature, this classname can be changed in future

  2. 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:closed
  • Created 7 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
plandemcommented, Jan 26, 2017

well, right now I’m using it like this (pass name prop manually):

import { Sider, Header, Footer, Content } from '../../components/layout';
....
			<Layout className='app'>
				<Sider name='Sider' {...siderProps}/>
				<Layout>
					<Header name='Header' {...headerProps} />
					<Content name='Content'>
						<div className='container'>
							<Router.Match path='/' handler={()=><div>aaaaa</div>}/>
							<Router.Miss handler={NotFound}/>
						</div>
					</Content>
					<Footer name='Footer'/>
				</Layout>
			</Layout>
0reactions
lock[bot]commented, May 2, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found