Skip to content

Commit c1d4666

Browse files
crisbetommalerba
authored andcommitted
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`.
1 parent f133da9 commit c1d4666

File tree

2 files changed

+11
-63
lines changed

2 files changed

+11
-63
lines changed

src/lib/sidenav/drawer.spec.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,22 +94,18 @@ describe('MatDrawer', () => {
9494
expect(getComputedStyle(drawerBackdropElement.nativeElement).visibility).toBe('hidden');
9595
}));
9696

97-
it('should resolve the open method promise with an object', fakeAsync(() => {
97+
it('should resolve the open method promise with the new state of the drawer', fakeAsync(() => {
9898
const fixture = TestBed.createComponent(BasicTestApp);
9999
fixture.detectChanges();
100100
const drawer = fixture.debugElement.query(By.directive(MatDrawer));
101101

102-
drawer.componentInstance.open().then(result => {
103-
expect(result).toBeTruthy();
104-
expect(result.type).toBe('open');
105-
expect(result.animationFinished).toBe(true);
106-
});
102+
drawer.componentInstance.open().then(result => expect(result).toBe('open'));
107103
fixture.detectChanges();
108104
tick();
109105
fixture.detectChanges();
110106
}));
111107

112-
it('should resolve the close method promise with an object', fakeAsync(() => {
108+
it('should resolve the close method promise with the new state of the drawer', fakeAsync(() => {
113109
const fixture = TestBed.createComponent(BasicTestApp);
114110
fixture.detectChanges();
115111
const drawer = fixture.debugElement.query(By.directive(MatDrawer));
@@ -119,11 +115,7 @@ describe('MatDrawer', () => {
119115
tick();
120116
fixture.detectChanges();
121117

122-
drawer.componentInstance.close().then(result => {
123-
expect(result).toBeTruthy();
124-
expect(result.type).toBe('close');
125-
expect(result.animationFinished).toBe(true);
126-
});
118+
drawer.componentInstance.close().then(result => expect(result).toBe('close'));
127119
fixture.detectChanges();
128120
tick();
129121
fixture.detectChanges();

src/lib/sidenav/drawer.ts

Lines changed: 7 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,8 @@ export function throwMatDuplicatedDrawerError(position: string) {
5454
}
5555

5656

57-
/**
58-
* Drawer toggle promise result.
59-
* @deprecated
60-
* @deletion-target 6.0.0
61-
*/
62-
export class MatDrawerToggleResult {
63-
constructor(
64-
/** Whether the drawer is opened or closed. */
65-
public type: 'open' | 'close',
66-
/** Whether the drawer animation is finished. */
67-
public animationFinished: boolean) {}
68-
}
57+
/** Result of the toggle promise that indicates the state of the drawer. */
58+
export type MatDrawerToggleResult = 'open' | 'close';
6959

7060
/** Configures whether drawers should use auto sizing by default. */
7161
export const MAT_DRAWER_DEFAULT_AUTOSIZE =
@@ -145,20 +135,11 @@ export class MatDrawer implements AfterContentInit, AfterContentChecked, OnDestr
145135
value = value === 'end' ? 'end' : 'start';
146136
if (value != this._position) {
147137
this._position = value;
148-
this.onAlignChanged.emit();
149138
this.onPositionChanged.emit();
150139
}
151140
}
152141
private _position: 'start' | 'end' = 'start';
153142

154-
/**
155-
* @deprecated
156-
* @deletion-target 6.0.0
157-
*/
158-
@Input()
159-
get align(): 'start' | 'end' { return this.position; }
160-
set align(value: 'start' | 'end') { this.position = value; }
161-
162143
/** Mode of the drawer; one of 'over', 'push' or 'side'. */
163144
@Input()
164145
get mode(): 'over' | 'push' | 'side' { return this._mode; }
@@ -218,29 +199,9 @@ export class MatDrawer implements AfterContentInit, AfterContentChecked, OnDestr
218199
);
219200
}
220201

221-
/**
222-
* Event emitted when the drawer is fully opened.
223-
* @deprecated Use `opened` instead.
224-
* @deletion-target 6.0.0
225-
*/
226-
@Output('open') readonly onOpen: Observable<void> = this._openedStream;
227-
228-
/**
229-
* Event emitted when the drawer is fully closed.
230-
* @deprecated Use `closed` instead.
231-
* @deletion-target 6.0.0
232-
*/
233-
@Output('close') readonly onClose: Observable<void> = this._closedStream;
234-
235202
/** Event emitted when the drawer's position changes. */
236203
@Output('positionChanged') onPositionChanged: EventEmitter<void> = new EventEmitter<void>();
237204

238-
/**
239-
* @deprecated
240-
* @deletion-target 6.0.0
241-
*/
242-
@Output('align-changed') onAlignChanged: EventEmitter<void> = new EventEmitter<void>();
243-
244205
/**
245206
* An observable that emits when the drawer mode changes. This is used by the drawer container to
246207
* 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
353314
* @param openedVia Whether the drawer was opened by a key press, mouse click or programmatically.
354315
* Used for focus management after the sidenav is closed.
355316
*/
356-
open(openedVia?: FocusOrigin): Promise<void> {
317+
open(openedVia?: FocusOrigin): Promise<MatDrawerToggleResult> {
357318
return this.toggle(true, openedVia);
358319
}
359320

360321
/** Close the drawer. */
361-
close(): Promise<void> {
322+
close(): Promise<MatDrawerToggleResult> {
362323
return this.toggle(false);
363324
}
364325

@@ -369,7 +330,7 @@ export class MatDrawer implements AfterContentInit, AfterContentChecked, OnDestr
369330
* Used for focus management after the sidenav is closed.
370331
*/
371332
toggle(isOpen: boolean = !this.opened, openedVia: FocusOrigin = 'program'):
372-
Promise<void> {
333+
Promise<MatDrawerToggleResult> {
373334

374335
this._opened = isOpen;
375336

@@ -385,13 +346,8 @@ export class MatDrawer implements AfterContentInit, AfterContentChecked, OnDestr
385346
this._focusTrap.enabled = this._isFocusTrapEnabled;
386347
}
387348

388-
// TODO(crisbeto): This promise is here for backwards-compatibility.
389-
// It should be removed next time we do breaking changes in the drawer.
390-
// @deletion-target 6.0.0
391-
return new Promise<any>(resolve => {
392-
this.openedChange.pipe(take(1)).subscribe(open => {
393-
resolve(new MatDrawerToggleResult(open ? 'open' : 'close', true));
394-
});
349+
return new Promise<MatDrawerToggleResult>(resolve => {
350+
this.openedChange.pipe(take(1)).subscribe(open => resolve(open ? 'open' : 'close'));
395351
});
396352
}
397353

0 commit comments

Comments
 (0)