-
Notifications
You must be signed in to change notification settings - Fork 6.8k
feat(sidenav): add responsive sidenav #6525
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
Changes from all commits
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 |
---|---|---|
|
@@ -23,6 +23,7 @@ import { | |
OnDestroy, | ||
Inject, | ||
ChangeDetectorRef, | ||
HostListener | ||
} from '@angular/core'; | ||
import {animate, state, style, transition, trigger, AnimationEvent} from '@angular/animations'; | ||
import {coerceBooleanProperty} from '@angular/cdk/coercion'; | ||
|
@@ -316,6 +317,35 @@ export class MdSidenavContainer implements AfterContentInit { | |
/** The sidenav child with the `end` alignment. */ | ||
get end() { return this._end; } | ||
|
||
/** | ||
* Width of the container at which it breaks | ||
* e.g., breakpointWidth="500" | ||
*/ | ||
@Input() breakpointWidth: number; | ||
|
||
/** Mode of the breakpoint; either true or false */ | ||
@Input() breakpointChangeMode: true | false = true; | ||
|
||
/** | ||
* Responsively toggle the sidenav using the breakpoint. | ||
* Note that this only works when the window is rezied. | ||
* If you resize it some other way, call checkBreakpoint(). | ||
*/ | ||
@HostListener('window:resize', ['$event']) | ||
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. This should be debounced. See https://github.com/angular/material2/blob/master/src/lib/tabs/tab-header.ts#L182-L195 |
||
checkBreakpoint() { | ||
if (this._element.nativeElement.offsetWidth < this.breakpointWidth) { | ||
if (this.breakpointChangeMode) | ||
this._sidenavs.forEach(sidenav => sidenav.mode = "over"); | ||
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. Use curly braces here and below |
||
this.close(); | ||
} | ||
if (this._element.nativeElement.offsetWidth > this.breakpointWidth) { | ||
if (this.breakpointChangeMode) | ||
this._sidenavs.forEach(sidenav => sidenav.mode = "side"); | ||
this.open(); | ||
} | ||
this._updateStyles(); | ||
} | ||
|
||
/** Event emitted when the sidenav backdrop is clicked. */ | ||
@Output() backdropClick = new EventEmitter<void>(); | ||
|
||
|
@@ -353,6 +383,7 @@ export class MdSidenavContainer implements AfterContentInit { | |
this._watchSidenavAlign(sidenav); | ||
}); | ||
}); | ||
this.checkBreakpoint(); | ||
} | ||
|
||
/** Calls `open` of both start and end sidenavs */ | ||
|
Uh oh!
There was an error while loading. Please reload this page.