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] Proper placement for anchor other than left #6516

Merged
merged 5 commits into from
Apr 8, 2017
Merged

[Drawer] Proper placement for anchor other than left #6516

merged 5 commits into from
Apr 8, 2017

Conversation

kgregory
Copy link
Member

@kgregory kgregory commented Apr 6, 2017

The anchor property is not fully implemented. It appropriately sets the direction that the drawer should slide, but the drawer is always placed at the left of the viewport. This is because the initial position and height is not changed when anchor is right, top, or bottom.

Resolution:

  • Assume a default of 'left'.
  • If we are right-to-left (based on the theme), swap 'right' and 'left'.
  • Create classes that extend paper for left, top, right, and bottom anchoring and apply them after possibly changing anchor in consideration of right-to-left.
  • For right anchored drawers, left is set to auto and right is set to zero. This follows the functionality employed in the master branch.
  • For top and bottom anchored drawers, height is set to auto, left and right are set to zero. The max height is left for the consumer of this component since Material Design does not prohibit a full-height bottom sheet.
  • A future PR may be required to ensure complete compliance with MD's standards for modal bottom sheets and ;ack of specification for modal top sheets.
  • Added top, bottom, right drawers to component demo.
  • PR has tests / docs demo, and is linted.
  • Commit and PR titles begin with [ComponentName], and are in imperative form: "[Component] Fix leaky abstraction".
  • Description explains the issue / use-case resolved, and auto-closes the related issue(s) (http://tr.im/vFqem).

- Assume a default of 'left'
- Check right to left, swap 'right' and 'left'
- Set initial placement and height based on the anchor property
- Consideration of right-to-left when anchor is set to right
- For top and bottom, height is set to auto, the max height is left for the consumer of this component since Material Design does not prevent a full-height bottom sheet.  No word on top sheets.
- Added top, bottom, right drawers to component demo.
@kgregory
Copy link
Member Author

kgregory commented Apr 6, 2017

Associated this PR with Issue #6517

@muibot muibot added PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI and removed PR: Needs Review labels Apr 6, 2017
- left anchor should switch to right
- right anchor should switch to left
@mbrookes mbrookes added component: drawer This is the name of the generic UI component, not the React module! and removed PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI labels Apr 6, 2017
Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, the demos are pretty cool. Thanks!


render() {
const classes = this.context.styleManager.render(styleSheet);
return (
<div>
<Button onClick={this.handleOpen}>Open Drawer</Button>
<Button onClick={this.handleTopOpen}>Open Top Drawer</Button>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have the left drawer first in the list as people will most likely try that one first.


render() {
const classes = this.context.styleManager.render(styleSheet);
return (
<div>
<Button onClick={this.handleOpen}>Open Drawer</Button>
<Button onClick={this.handleTopOpen}>Open Top Drawer</Button>
<Button onClick={this.handleLeftOpen}>Open Left Drawer</Button>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we can remove Drawer from the button wording, that's obvious and making it harder to read.

<ListItemText primary="Spam" />
</ListItem>
</List>
<div className={classes.remainder} />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we need a remainder.

onRequestClose={this.handleTopClose}
onClick={this.handleTopClose}
>
<List className={classes.listFull} padding={false}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The property changed, it's disablePadding

</ListItem>
</List>
<Divider />
<List className={classes.listFull} padding={false}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we should keep the children of the list DRY. Please use an intermediary constant.

@@ -126,7 +151,18 @@ export default class Drawer extends Component {
const { theme: { dir }, render } = this.context.styleManager;
const classes = render(styleSheet);
const rtl = dir === 'rtl';
const anchor = anchorProp || (rtl ? 'right' : 'left');
const anchorClasses = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could have been using smart code, but I guess a mapping is simpler here 👍

@oliviertassinari oliviertassinari added next PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI and removed PR: Needs Review labels Apr 7, 2017
- reordered buttons in drawer demo
- removed drawer from button label in demo
- eliminated remainder in demo
- made use of constant for reused list
- eliminated mapping, renamed classes to match acceptable values for anchor prop, apply appropriate class by using value of anchor as a key for the classes object
@kgregory
Copy link
Member Author

kgregory commented Apr 7, 2017

Thanks for reviewing, @oliviertassinari - I've pushed the requested changes.

@@ -140,7 +169,7 @@ export default class Drawer extends Component {
<Paper
elevation={docked ? 0 : elevation}
square
className={classNames(classes.paper, paperClassName)}
className={classNames(classes.paper, classes[anchor], paperClassName)}
Copy link
Member

@oliviertassinari oliviertassinari Apr 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now, I would call that a smart code, I'm not sure it's better as harder to debug, but if that what you prefer, I'm in 👍 .

- should have full width list for top and bottom
@oliviertassinari oliviertassinari added PR: Review Accepted and removed PR: Needs Review PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI labels Apr 7, 2017
@oliviertassinari oliviertassinari merged commit 17f0f84 into mui:next Apr 8, 2017
@oliviertassinari
Copy link
Member

@kgregory Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: drawer This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants