Skip to content

Commit

Permalink
fix(sidenav): treat opened as boolean attribute. (#444)
Browse files Browse the repository at this point in the history
Fixes #300.
  • Loading branch information
devversion authored and jelbourn committed May 16, 2016
1 parent be5e93a commit e977984
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
39 changes: 39 additions & 0 deletions src/components/sidenav/sidenav.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,45 @@ export function main() {
}).toThrow();
}));
});

describe('attributes', () => {

it('should correctly parse opened="false"', fakeAsyncAdaptor(() => {
let newBuilder = builder.overrideTemplate(BasicTestApp, `
<md-sidenav-layout>
<md-sidenav #sidenav mode="side" opened="false">
Closed Sidenav.
</md-sidenav>
</md-sidenav-layout>`);

let fixture = createFixture(BasicTestApp, newBuilder, template, style);
fixture.detectChanges();

let sidenavEl = fixture.debugElement.query(By.css('md-sidenav')).nativeElement;

expect(sidenavEl.classList).toContain('md-sidenav-closed');
expect(sidenavEl.classList).not.toContain('md-sidenav-opened');
}));

it('should correctly parse opened="true"', fakeAsyncAdaptor(() => {
let newBuilder = builder.overrideTemplate(BasicTestApp, `
<md-sidenav-layout>
<md-sidenav #sidenav mode="side" opened="true">
Closed Sidenav.
</md-sidenav>
</md-sidenav-layout>`);

let fixture = createFixture(BasicTestApp, newBuilder, template, style);
fixture.detectChanges();

let sidenavEl = fixture.debugElement.query(By.css('md-sidenav')).nativeElement;

expect(sidenavEl.classList).not.toContain('md-sidenav-closed');
expect(sidenavEl.classList).toContain('md-sidenav-opened');
}));

});

});
}

Expand Down
3 changes: 2 additions & 1 deletion src/components/sidenav/sidenav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import {Dir} from '../../core/rtl/dir';
import {PromiseCompleter} from '../../core/async/promise-completer';
import {MdError} from '../../core/errors/error';
import { BooleanFieldValue } from '../../core/annotations/field-value';


/**
Expand Down Expand Up @@ -50,7 +51,7 @@ export class MdSidenav {
@Input() mode: 'over' | 'push' | 'side' = 'over';

/** Whether the sidenav is opened. */
@Input('opened') private _opened: boolean = false;
@Input('opened') @BooleanFieldValue() private _opened: boolean = false;

/** Event emitted when the sidenav is being opened. Use this to synchronize animations. */
@Output('open-start') onOpenStart = new EventEmitter<void>();
Expand Down

0 comments on commit e977984

Please sign in to comment.