-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Responsive drawer #6535
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
Responsive drawer #6535
Changes from 5 commits
2ad5cd2
560e60d
267389b
d7d1214
759b31d
806bd8d
2b69f7b
c1f705f
47e698e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,10 +25,13 @@ import { | |
ChangeDetectorRef, | ||
} from '@angular/core'; | ||
import {animate, state, style, transition, trigger, AnimationEvent} from '@angular/animations'; | ||
import {Directionality, coerceBooleanProperty} from '../core'; | ||
import {Directionality, coerceBooleanProperty, coerceNumberProperty} from '../core'; | ||
import {FocusTrapFactory, FocusTrap} from '../core/a11y/focus-trap'; | ||
import {ESCAPE} from '../core/keyboard/keycodes'; | ||
import {first, takeUntil, startWith} from '../core/rxjs/index'; | ||
import {first, takeUntil, startWith, auditTime} from '../core/rxjs/index'; | ||
import {Subscription} from 'rxjs/subscription'; | ||
import {of as observableOf} from 'rxjs/observable/of'; | ||
import {fromEvent} from 'rxjs/observable/fromEvent'; | ||
import {DOCUMENT} from '@angular/platform-browser'; | ||
import {merge} from 'rxjs/observable/merge'; | ||
|
||
|
@@ -325,6 +328,31 @@ export class MdDrawerContainer implements AfterContentInit { | |
/** Event emitted when the drawer backdrop is clicked. */ | ||
@Output() backdropClick = new EventEmitter<void>(); | ||
|
||
/** Breakpoint width (in px) at which the sidenav collapses. */ | ||
|
||
@Input() | ||
get breakpointWidth() { return this._breakpointWidth; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jelbourn have you added anything to cdk yet for dealing with breakpoints? |
||
set breakpointWidth(v: number) { | ||
this._breakpointWidth = coerceNumberProperty(v, this._breakpointWidth); | ||
} | ||
private _breakpointWidth: number; | ||
|
||
/** Whether the drawer changes modes when collapsing. */ | ||
@Input() | ||
get breakpointChangeMode() { return this._breakpointChangeMode; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a quick question... why did you remove the return type here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It wasn't on the number one, so I removed it here |
||
set breakpointChangeMode(value: boolean) { | ||
this._breakpointChangeMode = coerceBooleanProperty(value); | ||
} | ||
private _breakpointChangeMode = true; | ||
|
||
/** | ||
* Responsively toggle the drawer using the breakpoint. | ||
* Note that this only works when the window is rezied. | ||
* If you resize it some other way, call _updateDrawer(). | ||
*/ | ||
private _updateDrawerSubscription: Subscription | null = null; | ||
private _updateDrawer() {} | ||
|
||
/** The drawer at the start/end position, independent of direction. */ | ||
private _start: MdDrawer | null; | ||
private _end: MdDrawer | null; | ||
|
@@ -359,6 +387,33 @@ export class MdDrawerContainer implements AfterContentInit { | |
this._watchDrawerPosition(drawer); | ||
}); | ||
}); | ||
|
||
const resize = typeof window !== 'undefined' ? | ||
auditTime.call(fromEvent(window, 'resize'), 150) : | ||
observableOf(null); | ||
|
||
this._updateDrawer = () => { | ||
if (this._element.nativeElement.offsetWidth < this.breakpointWidth) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't checked, but this needs to be consistent with any other responsive behavior in this lib or in flex-layout (i.e. |
||
if (this.breakpointChangeMode) { | ||
this._drawers.forEach(drawer => drawer.mode = 'over'); | ||
} | ||
this.close(); | ||
} | ||
if (this._element.nativeElement.offsetWidth > this.breakpointWidth) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't notice that, fixing. |
||
if (this.breakpointChangeMode) { | ||
this._drawers.forEach(drawer => drawer.mode = 'side'); | ||
} | ||
this.open(); | ||
} | ||
} | ||
this._updateDrawerSubscription = startWith.call(resize, null).subscribe(this._updateDrawer); | ||
|
||
} | ||
|
||
ngOnDestroy() { | ||
if (this._updateDrawerSubscription) { | ||
this._updateDrawerSubscription.unsubscribe(); | ||
} | ||
} | ||
|
||
/** Calls `open` of both start and end drawers */ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not so sure about this API, it doesn't seem to give much flexibility. You can't control what modes it switches between and you can't disable the auto-close/open feature