From c1d4666c47f022fb2115d41e6f6083a40f1eada5 Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Tue, 13 Mar 2018 12:00:50 -0400 Subject: [PATCH] refactor(sidenav): remove 6.0.0 deletion targets (#10279) Removes the deletion targets for 6.0.0 from the `material/drawer` entry point. BREAKING CHANGES: * The `MatDrawerToggleResult` class has been turned into an type. * The promise returned from `open`, `close` and `toggle` now resolves with the `MatDrawerToggleResult` type rather than the class. * `align` which was deprecated in 5.0.0 has been removed. Use `position` instead. * `open` which was deprecated in 5.0.0 has been removed. Use `opened` instead. * `close` which was deprecated in 5.0.0 has been removed. Use `closed` instead. * `align-changed` which was deprecated in 5.0.0 has been removed. Use `positionChanged`. --- src/lib/sidenav/drawer.spec.ts | 16 +++------- src/lib/sidenav/drawer.ts | 58 ++++------------------------------ 2 files changed, 11 insertions(+), 63 deletions(-) diff --git a/src/lib/sidenav/drawer.spec.ts b/src/lib/sidenav/drawer.spec.ts index 753ed646d64..7a43c7844dd 100644 --- a/src/lib/sidenav/drawer.spec.ts +++ b/src/lib/sidenav/drawer.spec.ts @@ -94,22 +94,18 @@ describe('MatDrawer', () => { expect(getComputedStyle(drawerBackdropElement.nativeElement).visibility).toBe('hidden'); })); - it('should resolve the open method promise with an object', fakeAsync(() => { + it('should resolve the open method promise with the new state of the drawer', fakeAsync(() => { const fixture = TestBed.createComponent(BasicTestApp); fixture.detectChanges(); const drawer = fixture.debugElement.query(By.directive(MatDrawer)); - drawer.componentInstance.open().then(result => { - expect(result).toBeTruthy(); - expect(result.type).toBe('open'); - expect(result.animationFinished).toBe(true); - }); + drawer.componentInstance.open().then(result => expect(result).toBe('open')); fixture.detectChanges(); tick(); fixture.detectChanges(); })); - it('should resolve the close method promise with an object', fakeAsync(() => { + it('should resolve the close method promise with the new state of the drawer', fakeAsync(() => { const fixture = TestBed.createComponent(BasicTestApp); fixture.detectChanges(); const drawer = fixture.debugElement.query(By.directive(MatDrawer)); @@ -119,11 +115,7 @@ describe('MatDrawer', () => { tick(); fixture.detectChanges(); - drawer.componentInstance.close().then(result => { - expect(result).toBeTruthy(); - expect(result.type).toBe('close'); - expect(result.animationFinished).toBe(true); - }); + drawer.componentInstance.close().then(result => expect(result).toBe('close')); fixture.detectChanges(); tick(); fixture.detectChanges(); diff --git a/src/lib/sidenav/drawer.ts b/src/lib/sidenav/drawer.ts index 9fb1799c622..e7923f45117 100644 --- a/src/lib/sidenav/drawer.ts +++ b/src/lib/sidenav/drawer.ts @@ -54,18 +54,8 @@ export function throwMatDuplicatedDrawerError(position: string) { } -/** - * Drawer toggle promise result. - * @deprecated - * @deletion-target 6.0.0 - */ -export class MatDrawerToggleResult { - constructor( - /** Whether the drawer is opened or closed. */ - public type: 'open' | 'close', - /** Whether the drawer animation is finished. */ - public animationFinished: boolean) {} -} +/** Result of the toggle promise that indicates the state of the drawer. */ +export type MatDrawerToggleResult = 'open' | 'close'; /** Configures whether drawers should use auto sizing by default. */ export const MAT_DRAWER_DEFAULT_AUTOSIZE = @@ -145,20 +135,11 @@ export class MatDrawer implements AfterContentInit, AfterContentChecked, OnDestr value = value === 'end' ? 'end' : 'start'; if (value != this._position) { this._position = value; - this.onAlignChanged.emit(); this.onPositionChanged.emit(); } } private _position: 'start' | 'end' = 'start'; - /** - * @deprecated - * @deletion-target 6.0.0 - */ - @Input() - get align(): 'start' | 'end' { return this.position; } - set align(value: 'start' | 'end') { this.position = value; } - /** Mode of the drawer; one of 'over', 'push' or 'side'. */ @Input() get mode(): 'over' | 'push' | 'side' { return this._mode; } @@ -218,29 +199,9 @@ export class MatDrawer implements AfterContentInit, AfterContentChecked, OnDestr ); } - /** - * Event emitted when the drawer is fully opened. - * @deprecated Use `opened` instead. - * @deletion-target 6.0.0 - */ - @Output('open') readonly onOpen: Observable = this._openedStream; - - /** - * Event emitted when the drawer is fully closed. - * @deprecated Use `closed` instead. - * @deletion-target 6.0.0 - */ - @Output('close') readonly onClose: Observable = this._closedStream; - /** Event emitted when the drawer's position changes. */ @Output('positionChanged') onPositionChanged: EventEmitter = new EventEmitter(); - /** - * @deprecated - * @deletion-target 6.0.0 - */ - @Output('align-changed') onAlignChanged: EventEmitter = new EventEmitter(); - /** * An observable that emits when the drawer mode changes. This is used by the drawer container to * to know when to when the mode changes so it can adapt the margins on the content. @@ -353,12 +314,12 @@ export class MatDrawer implements AfterContentInit, AfterContentChecked, OnDestr * @param openedVia Whether the drawer was opened by a key press, mouse click or programmatically. * Used for focus management after the sidenav is closed. */ - open(openedVia?: FocusOrigin): Promise { + open(openedVia?: FocusOrigin): Promise { return this.toggle(true, openedVia); } /** Close the drawer. */ - close(): Promise { + close(): Promise { return this.toggle(false); } @@ -369,7 +330,7 @@ export class MatDrawer implements AfterContentInit, AfterContentChecked, OnDestr * Used for focus management after the sidenav is closed. */ toggle(isOpen: boolean = !this.opened, openedVia: FocusOrigin = 'program'): - Promise { + Promise { this._opened = isOpen; @@ -385,13 +346,8 @@ export class MatDrawer implements AfterContentInit, AfterContentChecked, OnDestr this._focusTrap.enabled = this._isFocusTrapEnabled; } - // TODO(crisbeto): This promise is here for backwards-compatibility. - // It should be removed next time we do breaking changes in the drawer. - // @deletion-target 6.0.0 - return new Promise(resolve => { - this.openedChange.pipe(take(1)).subscribe(open => { - resolve(new MatDrawerToggleResult(open ? 'open' : 'close', true)); - }); + return new Promise(resolve => { + this.openedChange.pipe(take(1)).subscribe(open => resolve(open ? 'open' : 'close')); }); }