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

Fixed menu inside a Sidebar pushable? #1646

Closed
RhanCandia opened this issue Apr 30, 2017 · 6 comments
Closed

Fixed menu inside a Sidebar pushable? #1646

RhanCandia opened this issue Apr 30, 2017 · 6 comments

Comments

@RhanCandia
Copy link

RhanCandia commented Apr 30, 2017

I've been stuck here. Basically, I added a fixed menu inside a sidebar pushable like so:

Sidebar.js

<Sidebar.Pushable as={ Segment }>
    <Sidebar as={ Menu } animation="overlay" width='thin'
             visible={ app.sidebarVisibility } icon='labeled'
             vertical inverted>
        <Menu.Item onClick={ () => ( app.sidebarVisibility && onToggleSidebar() ) }
                   as={ NavLink } exact to="/">
            Home
        </Menu.Item>
        <Menu.Item onClick={ () => ( app.sidebarVisibility && onToggleSidebar() ) }
                   as={ NavLink } to="/menu">
            Menu
        </Menu.Item>
    </Sidebar>
    <Sidebar.Pusher onClick={ () => ( app.sidebarVisibility && onToggleSidebar() ) }>
        <Container className="Main-container">
            <Segment basic>
                <NavBar app={ app } onToggleSidebar={ onToggleSidebar } />
                { children }
            </Segment>
        </Container>
    </Sidebar.Pusher>
</Sidebar.Pushable>

NavBar.js

<Menu borderless fixed="top">
    { app.device && app.device.type === 'mobile' &&
    <Menu.Item>
        <Button basic icon="sidebar"
                onClick={ () => ( !app.sidebarVisibility && onToggleSidebar() ) } />
    </Menu.Item>
    }
    <Menu.Item header>Krispy Kreme</Menu.Item>
    { app.device && app.device.type !== 'mobile' &&
    <Menu.Menu>
        <Menu.Item as={ NavLink } to="/" exact>Home</Menu.Item>
        <Menu.Item as={ NavLink } to="/menu">Menu</Menu.Item>
    </Menu.Menu>
    }
    <Menu.Menu position="right">
        <Menu.Item>
            <Button basic icon="cart" label={ <Label color="red"> { cartItems } </Label> } />
        </Menu.Item>
    </Menu.Menu>
</Menu>

EDIT:

I was able to fix it by using flex layouts.

Basically, I had to make the Segment component inside the Sidebar.Pusher use display: flex with flex-direction: column so I can lay the contents properly. Then I gave it two children, the NavBar and the Content. I gave Content a flex-grow: 1 property. Now The header stays on top. Here's how it looks like now:

<Sidebar.Pusher onClick={ () => ( app.sidebarVisibility && onToggleSidebar() ) }>
    <Segment basic>
        <NavBar app={ app } onToggleSidebar={ onToggleSidebar } />
        <Content>
            { children }
        </Content>
    </Segment>
</Sidebar.Pusher>
@RhanCandia
Copy link
Author

I got what I want by using flex.

@mairh
Copy link

mairh commented May 2, 2017

@RhanCandia It would be nice to update the issue with the correct answer so that other people can follow it in the future.

@RhanCandia
Copy link
Author

@mairh I updated my opening post to explain how I fixed it. Thanks for reminding me.

@Shurlow
Copy link

Shurlow commented Apr 12, 2018

@RhanCandia I am having the same issue but your solution isn't working for me. Any chance you could post the full code, including css? Thanks!

@tiagowippel
Copy link

I was unable to use this solution too.

@Roshini369
Copy link

Roshini369 commented Dec 17, 2019

@RhanCandia Can you upload the full code. I am facing the problem of fixed=top menu not working in navbar. it would be nice if you show the code of adding flex alone of content used inside sidebar.pusher

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

No branches or pull requests

5 participants