Skip to content
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

feat(snack-bar): allow setting the layout direction #4726

Merged
merged 3 commits into from May 23, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/lib/snack-bar/simple-snack-bar.scss
Expand Up @@ -28,4 +28,9 @@ $mat-snack-bar-button-margin: 48px !default;
size: inherit;
weight: 600;
}

/deep/ [dir='rtl'] & {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to avoid having /deep/ anywhere in the library.
(and prefer turning off ViewEncapsulation)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Also fixed the button not being uppercase for some reason.

margin-right: $mat-snack-bar-button-margin;
margin-left: 0;
}
}
5 changes: 4 additions & 1 deletion src/lib/snack-bar/snack-bar-config.ts
@@ -1,5 +1,5 @@
import {ViewContainerRef} from '@angular/core';
import {AriaLivePoliteness} from '../core';
import {AriaLivePoliteness, LayoutDirection} from '../core';

/**
* Configuration used when opening a snack-bar.
Expand All @@ -19,4 +19,7 @@ export class MdSnackBarConfig {

/** Extra CSS classes to be added to the snack bar container. */
extraClasses?: string[];

/** Text layout direction for the snack bar. */
direction?: LayoutDirection = 'ltr';
}
59 changes: 34 additions & 25 deletions src/lib/snack-bar/snack-bar.spec.ts
Expand Up @@ -309,36 +309,45 @@ describe('MdSnackBar', () => {
tick(500);
}));

it('should dismiss automatically after a specified timeout', fakeAsync(() => {
let dismissObservableCompleted = false;
let config = new MdSnackBarConfig();
config.duration = 250;
let snackBarRef = snackBar.open('content', 'test', config);
snackBarRef.afterDismissed().subscribe(() => {
dismissObservableCompleted = true;
});
it('should dismiss automatically after a specified timeout', fakeAsync(() => {
let dismissObservableCompleted = false;
let config = new MdSnackBarConfig();
config.duration = 250;
let snackBarRef = snackBar.open('content', 'test', config);
snackBarRef.afterDismissed().subscribe(() => {
dismissObservableCompleted = true;
});

viewContainerFixture.detectChanges();
flushMicrotasks();
expect(dismissObservableCompleted).toBeFalsy('Expected the snack bar not to be dismissed');
viewContainerFixture.detectChanges();
flushMicrotasks();
expect(dismissObservableCompleted).toBeFalsy('Expected the snack bar not to be dismissed');

tick(1000);
viewContainerFixture.detectChanges();
flushMicrotasks();
expect(dismissObservableCompleted).toBeTruthy('Expected the snack bar to be dismissed');
}));
tick(1000);
viewContainerFixture.detectChanges();
flushMicrotasks();
expect(dismissObservableCompleted).toBeTruthy('Expected the snack bar to be dismissed');
}));

it('should add extra classes to the container', () => {
snackBar.open(simpleMessage, simpleActionLabel, {
viewContainerRef: testViewContainerRef,
extraClasses: ['one', 'two']
});
it('should add extra classes to the container', () => {
snackBar.open(simpleMessage, simpleActionLabel, {
viewContainerRef: testViewContainerRef,
extraClasses: ['one', 'two']
});

let containerClasses = overlayContainerElement.querySelector('snack-bar-container').classList;
let containerClasses = overlayContainerElement.querySelector('snack-bar-container').classList;

expect(containerClasses).toContain('one');
expect(containerClasses).toContain('two');
});

it('should set the layout direction', () => {
snackBar.open(simpleMessage, simpleActionLabel, { direction: 'rtl' });

let pane = overlayContainerElement.querySelector('.cdk-overlay-pane');

expect(pane.getAttribute('dir')).toBe('rtl', 'Expected the pane to be in RTL mode.');
});

expect(containerClasses).toContain('one');
expect(containerClasses).toContain('two');
});
});

describe('MdSnackBar with parent MdSnackBar', () => {
Expand Down
10 changes: 5 additions & 5 deletions src/lib/snack-bar/snack-bar.ts
Expand Up @@ -54,7 +54,7 @@ export class MdSnackBar {
*/
openFromComponent<T>(component: ComponentType<T>, config?: MdSnackBarConfig): MdSnackBarRef<T> {
config = _applyConfigDefaults(config);
let overlayRef = this._createOverlay();
let overlayRef = this._createOverlay(config);
let snackBarContainer = this._attachSnackBarContainer(overlayRef, config);
let snackBarRef = this._attachSnackbarContent(component, snackBarContainer, overlayRef);

Expand Down Expand Up @@ -139,12 +139,12 @@ export class MdSnackBar {

/**
* Creates a new overlay and places it in the correct location.
* @param config The user-specified snack bar config.
*/
private _createOverlay(): OverlayRef {
private _createOverlay(config: MdSnackBarConfig): OverlayRef {
let state = new OverlayState();
state.positionStrategy = this._overlay.position().global()
.centerHorizontally()
.bottom('0');
state.direction = config.direction;
state.positionStrategy = this._overlay.position().global().centerHorizontally().bottom('0');
return this._overlay.create(state);
}
}
Expand Down