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

[Drawer] Is there support for a pinned / stacked sidebar? #4752

Closed
tgoldenberg opened this issue Jul 20, 2016 · 21 comments
Closed

[Drawer] Is there support for a pinned / stacked sidebar? #4752

tgoldenberg opened this issue Jul 20, 2016 · 21 comments
Labels
new feature New feature or request

Comments

@tgoldenberg
Copy link

Description

When I open the Drawer component, I would like it to not overlay on top of my layout, but push the content sideways. Similar to the sliding nav functionality in this example - http://react-toolbox.com/#/components/layout

Versions

Using React 15.2 with material-ui 15.2. Also using Meteor.

-->

@aahan96
Copy link
Contributor

aahan96 commented Jul 20, 2016

@tgoldenberg Google material design doesn't support such kind of drawers. Have a look at this: https://material.google.com/patterns/navigation-drawer.html#navigation-drawer-content

@aahan96 aahan96 closed this as completed Jul 20, 2016
@aahan96 aahan96 reopened this Jul 20, 2016
@skirunman
Copy link
Contributor

I was going to ask the same question and the google spec does seem to say that only drawers of type Temporary should overlay the content. Drawers of type Permanent, Persistent and Mini variant all push the content to the right.

@skirunman
Copy link
Contributor

See #3415 which says you can do this with setting zDepth prop.

@tgoldenberg
Copy link
Author

@skirunman I'm not sure zDepth allows me to change this. Since position is set to fixed, even if I change zDepth as #3415 suggests, it doesn't push my content to the right when open (the "persistent" example in MD). Is there an example of what you are suggesting?

@skirunman
Copy link
Contributor

skirunman commented Jul 20, 2016

No, I don't have an example as I was just researching if Material-UI would work for our Meteor/React app when I saw your question. We definitely need support for Persistent style of Drawer for our web app as well.

Maybe pass in additional styling to the Drawer component?

@tgoldenberg
Copy link
Author

@aahan96 Any comments on this? It appears that Material Design does support persistent sidebars. I am sure other people are looking for this functionality besides myself...

@aahan96
Copy link
Contributor

aahan96 commented Jul 20, 2016

@tgoldenberg You are right. After commenting on the issue, I checked the material design website and got to know about Persistent menus and that's why I reopened the issue. I think this feature should exist. Do you have any PRs to submit for this new feature?

@aahan96 aahan96 added the new feature New feature or request label Jul 20, 2016
@tgoldenberg
Copy link
Author

@aahan96 I'm not familiar enough with the codebase to do that. It seems like an issue that someone with advanced css knowledge might be able to solve. I just adopted material-ui pretty recently. Hoping this issue gets some attention and some help.

@skirunman
Copy link
Contributor

After looking at this a bit I think it would be nice to have 2 more props for the Drawer component so it would be easier to support all the google material navigation drawer styles. So something like:

  1. clipped = sets height of drawer to 100% minus the height of the app bar (64px by default) so it does not overlay the app bar.
  2. pushContent = sets left (or right) margin of the main body content to the width of the drawer so the drawer pushes content instead of overlaying it.

Just an idea.

@skirunman
Copy link
Contributor

This seems related #157

@carlosbaraza
Copy link

Any news about this feature? Roadmap?

@skirunman
Copy link
Contributor

We ended up implementing this ourselves in our LayoutDrawer.js component. Maybe this will help someone else. FYI, we also are using Meteor.js.

import {Meteor} from 'meteor/meteor';

import React, {PropTypes} from 'react';
import {Link} from 'react-router';

import Divider from 'material-ui/Divider';
import Drawer from 'material-ui/Drawer';
import Help from 'material-ui/svg-icons/action/help';
import MenuItem from 'material-ui/MenuItem';
import Settings from 'material-ui/svg-icons/action/settings';
import withWidth, {LARGE} from 'material-ui/utils/withWidth';

import {navigation} from './Layout';
import UserCardHeader from '/imports/client/components/UserCardHeader';

const {settings: {'public': {supportUrl} = {}} = {}} = Meteor;

export const LayoutDrawer = ({children, width, ...props}, {isDrawerOpened, onDrawerOpened}) => (
  <Drawer
    docked={width === LARGE}
    open={width === LARGE || isDrawerOpened}
    onRequestChange={onDrawerOpened}
    {...props}
  >
    <UserCardHeader />
    {width === LARGE && navigation.map(({label, icon: Icon, path}) =>
      <MenuItem key={label} primaryText={label} leftIcon={<Icon />} containerElement={<Link to={path} />} />
    )}
    {children}
    <Divider />
    <MenuItem leftIcon={<Settings />} primaryText="Settings" containerElement={<Link to="/settings" />} />
    <MenuItem leftIcon={<Help />} primaryText="Help & Feedback" href={supportUrl} target="_blank" />
  </Drawer>
);

LayoutDrawer.propTypes = {
  width: PropTypes.number,
  children: PropTypes.node
};

LayoutDrawer.contextTypes = {
  isDrawerOpened: PropTypes.bool.isRequired,
  onDrawerOpened: PropTypes.func.isRequired
};

export default withWidth()(LayoutDrawer);

@nguyenbathanh
Copy link

nguyenbathanh commented Dec 16, 2016

I figured out a trick to do this, see my example and code below:

bgggg

import React from 'react'
import {List, ListItem} from 'material-ui/List'
import ActionGrade from 'material-ui/svg-icons/action/grade'
import ContentInbox from 'material-ui/svg-icons/content/inbox'
import ContentDrafts from 'material-ui/svg-icons/content/drafts'
import ContentSend from 'material-ui/svg-icons/content/send'
import Subheader from 'material-ui/Subheader'
import Toggle from 'material-ui/Toggle'
import darkBaseTheme from 'material-ui/styles/baseThemes/darkBaseTheme'
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider'
import getMuiTheme from 'material-ui/styles/getMuiTheme'
import classnames from 'classnames'

export class MyComponent extends React.Component {
  constructor(props){
    super(props)
    this.state = {open: true}
    this.handleToggle = this.handleToggle.bind(this)
    this.handleClose = this.handleClose.bind(this)
  }

  handleToggle() {
    this.setState({open: !this.state.open})
  }

  handleClose() {
    this.setState({open: true})
  }

  render(){
    return (
      <div>
         <MuiThemeProvider muiTheme={getMuiTheme()}>
         <div>
            <AppBar
            className={classnames('app-bar', {'expanded': this.state.open})}
            onLeftIconButtonTouchTap={this.handleToggle}
            title="How long have you been alive?"
            iconElementRight={<RightBar />}
            />
            <Drawer
            docked={true}
            open={this.state.open}
            onRequestChange={(open) => this.setState({open})}
            >
          <List>
            <Subheader>Nested List Items</Subheader>
            <ListItem primaryText="Sent mail" leftIcon={<ContentSend />} />
            <ListItem primaryText="Drafts" leftIcon={<ContentDrafts />} />
            <ListItem
              primaryText="Inbox"
              leftIcon={<ContentInbox />}
              initiallyOpen={true}
              primaryTogglesNestedList={true}
              nestedItems={[
                <ListItem
                  key={1}
                  primaryText="Starred"
                  leftIcon={<ActionGrade />}
                />,
                <ListItem
                  key={2}
                  primaryText="Sent Mail"
                  leftIcon={<ContentSend />}
                  disabled={true}
                  nestedItems={[
                    <ListItem key={1} primaryText="Drafts" leftIcon={<ContentDrafts />} />,
                  ]}
                />,
                <ListItem
                  key={3}
                  primaryText="Inbox"
                  leftIcon={<ContentInbox />}
                  open={this.state.open}
                  onNestedListToggle={this.handleNestedListToggle}
                  nestedItems={[
                    <ListItem key={1} primaryText="Drafts" leftIcon={<ContentDrafts />} />,
                  ]}
                />,
              ]}
            />
          </List>
        </Drawer>
          { this.props.isAuthenticated && <div className={classnames('app-content', {'expanded': this.state.open})}> { this.props.children } </div>}
        </div>
      </MuiThemeProvider>
      </div>
    )
  }
}

and the css style:

.app-bar{
  -moz-transition: left 218ms cubic-bezier(0.4, 0, 0.2, 1);
  -o-transition: left 218ms cubic-bezier(0.4, 0, 0.2, 1);
  -webkit-transition: left 218ms cubic-bezier(0.4, 0, 0.2, 1);
  transition: left 218ms cubic-bezier(0.4, 0, 0.2, 1);
  left: 0;
  width: auto !important;
  right: 0 !important;
  position: fixed !important;
}

.app-content{
  -moz-transition: padding-left 218ms cubic-bezier(0.4, 0, 0.2, 1);
  -o-transition: padding-left 218ms cubic-bezier(0.4, 0, 0.2, 1);
  -webkit-transition: padding-left 218ms cubic-bezier(0.4, 0, 0.2, 1);
  transition: padding-left 218ms cubic-bezier(0.4, 0, 0.2, 1);
  padding-right: 20px !important;
  padding-top: 64px !important;
}

.app-bar.expanded{
  left: 255px;
}

.app-content.expanded{
  padding-left: 255px;
}

@ryanbelke
Copy link

ryanbelke commented Apr 26, 2017

I was able to get @nguyenbathanh code working above with some modifications. Mainly I put all of the content that I want to slide when opened in a container div called app-root.

<div className={INSERT TEMPLATE LITERAL HERE app-root ${(this.state.open ? ' expanded' : '')} INSERT TEMPLATE LITERAL HERE }>

Full Code/CSS

<div style={styles.container}>

       <Drawer open={this.state.open}
               width={120}
       >
         <MenuItem>
           <h4>Content</h4>
           <Contents {...{ actions, data, cssTransitionGroupClassNames }} />
         </MenuItem>

       </Drawer>
       <div className={`app-root  ${(this.state.open ? ' expanded' : '')}` }>

       <Toolbar>
         <ToolbarGroup firstChild={true}>
           <RaisedButton
             label="Show Content"
             onTouchTap={this.handleToggle}

           />
           <ToolbarSeparator />

           <RaisedButton label="Manage Content" />
         <ToolbarSeparator />
         <RaisedButton label="Manage More Content" />

         </ToolbarGroup>


       </Toolbar>
    
     </div>
     </div>

CSS
.app-root{
 -moz-transition: left 218ms cubic-bezier(0.4, 0, 0.2, 1);
 -o-transition: left 218ms cubic-bezier(0.4, 0, 0.2, 1);
 -webkit-transition: left 218ms cubic-bezier(0.4, 0, 0.2, 1);
 transition: left 218ms cubic-bezier(0.4, 0, 0.2, 1);
 left: 0;
 width: auto !important;
 right: 0 !important;
 position: fixed !important;
}

.app-root.expanded{
 left: 255px;
}

@rishikilaru
Copy link

rishikilaru commented May 8, 2017

@Zuurkern
Copy link

@rishikilaru I am working on implementing all types of drawers in the Material Design Guidelines. I am almost finished and will open a PR soon. However, these changes are based off the next branch.

@brion-fuller
Copy link

How is the progress of the drawers going?

@Sewdn
Copy link

Sewdn commented May 17, 2017

@brion-fuller its done! #6878 needs to be reviewed and merged still

@oliviertassinari oliviertassinari changed the title Is there support for a pinned / stacked sidebar? [Drawer] Is there support for a pinned / stacked sidebar? May 19, 2017
@oliviertassinari
Copy link
Member

Closed by #7925

@pselden
Copy link

pselden commented Feb 8, 2018

Sorry to necro this thread, but is there an example that anyone has where it doesn't push the app bar when it opens, like in Google Inbox?

@bijay-shrestha
Copy link

bijay-shrestha commented Jun 10, 2019

I figured out a trick to do this, see my example and code below:

bgggg

It is not working

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

No branches or pull requests