-
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 |
---|---|---|
|
@@ -28,7 +28,10 @@ import {animate, state, style, transition, trigger, AnimationEvent} from '@angul | |
import {Directionality, coerceBooleanProperty} 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,27 @@ export class MdDrawerContainer implements AfterContentInit { | |
/** Event emitted when the drawer backdrop is clicked. */ | ||
@Output() backdropClick = new EventEmitter<void>(); | ||
|
||
/** | ||
* Width of the container at which it breaks | ||
* e.g., breakpointWidth="500" | ||
*/ | ||
@Input() breakpointWidth: number; | ||
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. |
||
|
||
/** Whether the drawer changes modes when collapsing. */ | ||
@Input() | ||
get breakpointChangeMode(): boolean { return this._breakpointChangeMode; } | ||
set breakpointChangeMode(value: boolean) { | ||
this._breakpointChangeMode = coerceBooleanProperty(value); | ||
} | ||
private _breakpointChangeMode: boolean = true; | ||
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. Type should be implicit 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(). | ||
*/ | ||
_updateDrawer: Subscription | null = null; | ||
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. Maybe rename this to |
||
|
||
/** The drawer at the start/end position, independent of direction. */ | ||
private _start: MdDrawer | null; | ||
private _end: MdDrawer | null; | ||
|
@@ -359,6 +383,33 @@ export class MdDrawerContainer implements AfterContentInit { | |
this._watchDrawerPosition(drawer); | ||
}); | ||
}); | ||
|
||
const resize = typeof window !== 'undefined' ? | ||
auditTime.call(fromEvent(window, 'resize'), 150) : | ||
observableOf(null); | ||
|
||
this._updateDrawer = startWith.call(resize, null).subscribe(() => { | ||
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(); | ||
} | ||
}); | ||
|
||
} | ||
|
||
ngOnDestroy() { | ||
if (this._updateDrawer) { | ||
this._updateDrawer.unsubscribe(); | ||
this._updateDrawer = null; | ||
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 don't think setting to |
||
} | ||
} | ||
|
||
/** 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.
Maybe just,