-
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
Closed
Closed
Responsive drawer #6535
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2ad5cd2
Merge pull request #1 from angular/master
oliver-ni 560e60d
feat(drawer): add responsive drawer
oliver-ni 267389b
fix(drawer): typo "the the"
oliver-ni d7d1214
fix(drawer): fix code style and accidental bug
oliver-ni 759b31d
fix(drawer): fix subscription import
oliver-ni 806bd8d
refactor(drawer): change double if to if-else
oliver-ni 2b69f7b
fix(drawer): fixed responsive drawer code
oliver-ni c1f705f
Merge branch 'responsive-drawer' of https://github.com/mcparadip/mate…
oliver-ni 47e698e
refactor(drawer): fix lint issues
oliver-ni File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
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,32 @@ 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) { | ||
if (this.breakpointChangeMode) { | ||
this._drawers.forEach(drawer => drawer.mode = 'over'); | ||
} | ||
this.close(); | ||
} else { | ||
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 */ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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