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(md-snack-bar): Create initial MdSnackBar. #1296

Merged
merged 1 commit into from
Sep 23, 2016

Conversation

josephperrott
Copy link
Member

For #115

@googlebot googlebot added cla: yes PR author has agreed to Google's Contributor License Agreement labels Sep 21, 2016
@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request) and all commit authors, but as best as we can tell these commits were authored by someone else. If that's the case, please add them to this pull request and have them confirm that they're okay with these commits being contributed to Google. If we're mistaken and you did author these commits, just reply here to confirm.

1 similar comment
@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request) and all commit authors, but as best as we can tell these commits were authored by someone else. If that's the case, please add them to this pull request and have them confirm that they're okay with these commits being contributed to Google. If we're mistaken and you did author these commits, just reply here to confirm.

@googlebot googlebot added cla: no PR author must sign Google's Contributor License Agreement: https://opensource.google.com/docs/cla and removed cla: yes PR author has agreed to Google's Contributor License Agreement labels Sep 21, 2016
@googlebot
Copy link

CLAs look good, thanks!

1 similar comment
@googlebot
Copy link

CLAs look good, thanks!

@googlebot googlebot added cla: yes PR author has agreed to Google's Contributor License Agreement and removed cla: no PR author must sign Google's Contributor License Agreement: https://opensource.google.com/docs/cla labels Sep 21, 2016
Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

For unit tests, you should be able to do pretty much the same thing as dialog.

padding: 5px;
text-transform: uppercase;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Can you refactor this to be like:

md-simple-snackbar {
  display: flex;
  justify-content: space-between;
}

.md-simple-snackbar-message {
  ...
}

.md-simple-snackbar-action {
  ...
}

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

</div>
</div>

<button md-raised-button (click)="open()">Open</button>
Copy link
Member

Choose a reason for hiding this comment

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

OPEN all caps

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

<div>
<md-checkbox [(ngModel)]="action">Show button</md-checkbox>
<md-input type="text" class="button-label-input"
placeholder="Button Label"
Copy link
Member

Choose a reason for hiding this comment

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

placeholder="Snackbar action label"

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

import {MdSnackBarRef} from './snack-bar-ref';


export class BaseSnackBarContent<T> {
Copy link
Member

Choose a reason for hiding this comment

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

What's this base class for, since it's only ever inherited by from SimpleSnackbar?

Copy link
Member Author

Choose a reason for hiding this comment

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

Custom components used for snack bar content would also need to inherit from BaseSnackBarContent as it defines the MdSnackBarRef attributes on the component as well as a dismiss method to dismiss the snack bar.

Copy link
Member

Choose a reason for hiding this comment

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

I don't want to require that any component you open in the sidenav inherits / implements anything. Inheritance is especially problematic because your component might already inherit from something else.

All of the end-developer's interactions with the snackbar should be done through the SnackBarRef

Copy link
Member Author

Choose a reason for hiding this comment

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

Gotcha, I was wanting to make sure that the MdSnackBarRef was available to every component it opens, but that can be the responsibility of the end-dev

Copy link
Member

Choose a reason for hiding this comment

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

In the dialog, we just make the MDDialogRef available for injection into the component (see DialogInjector). You don't have to worry about this for now, though.

@@ -0,0 +1,29 @@
{
"name": "@angular2-material/snack-bar",
"version": "2.0.0-alpha.8-1",
Copy link
Member

Choose a reason for hiding this comment

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

alpha.8-2 (here and below)

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

*/
open(message: string, buttonLabel: string,
config: MdSnackBarConfig): MdSnackBarRef<SimpleSnackBar> {
let simpleSnackBar = this.openFromComponent(SimpleSnackBar, config);
Copy link
Member

Choose a reason for hiding this comment

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

simpleSnackbarRef

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

/**
* Creates and dispatches a snack bar.
*/
open(message: string, buttonLabel: string,
Copy link
Member

Choose a reason for hiding this comment

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

buttonLabel > actionLabel ?

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

* Creates and dispatches a snack bar.
*/
open(message: string, buttonLabel: string,
config: MdSnackBarConfig): MdSnackBarRef<SimpleSnackBar> {
Copy link
Member

Choose a reason for hiding this comment

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

config should be optional

Copy link
Member Author

Choose a reason for hiding this comment

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

Because the config includes the viewContainerRef, it will always need to be included.

state.positionStrategy = this._overlay.position().global()
.fixed()
.centerHorizontally()
.bottom('0px');
Copy link
Member

Choose a reason for hiding this comment

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

I think you can just do '0'

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

/**
* Places a new component as the content of the snack bar container.
*/
private _fillSnackBarContainer<T>(component: ComponentType<T>,
Copy link
Member

Choose a reason for hiding this comment

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

_attachSnackbarContent?

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

import {MdSnackBarRef} from './snack-bar-ref';


export class BaseSnackBarContent<T> {
Copy link
Member

Choose a reason for hiding this comment

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

I don't want to require that any component you open in the sidenav inherits / implements anything. Inheritance is especially problematic because your component might already inherit from something else.

All of the end-developer's interactions with the snackbar should be done through the SnackBarRef

"peerDependencies": {
"@angular2-material/core": "2.0.0-alpha.8-2"
}
}
Copy link
Member

Choose a reason for hiding this comment

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

You can delete this file, we won't need it for alpha.9

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

@@ -0,0 +1,28 @@
md-simple-snackbar {
display: flex;
Copy link
Member

Choose a reason for hiding this comment

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

Too much indent

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


export class MdSnackBarConfig {
/** The aria-role of the snack bar. */
role: SnackBarRole = 'alert';
Copy link
Member

Choose a reason for hiding this comment

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

'polite' isn't a valid role value. This should be used as the politeness that's passed through to the MdLiveAnnouncer

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request) and all commit authors, but as best as we can tell these commits were authored by someone else. If that's the case, please add them to this pull request and have them confirm that they're okay with these commits being contributed to Google. If we're mistaken and you did author these commits, just reply here to confirm.

1 similar comment
@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request) and all commit authors, but as best as we can tell these commits were authored by someone else. If that's the case, please add them to this pull request and have them confirm that they're okay with these commits being contributed to Google. If we're mistaken and you did author these commits, just reply here to confirm.

@googlebot googlebot added cla: no PR author must sign Google's Contributor License Agreement: https://opensource.google.com/docs/cla and removed cla: yes PR author has agreed to Google's Contributor License Agreement labels Sep 22, 2016
@jelbourn jelbourn added the cla: yes PR author has agreed to Google's Contributor License Agreement label Sep 22, 2016
@googlebot googlebot added cla: no PR author must sign Google's Contributor License Agreement: https://opensource.google.com/docs/cla and removed cla: yes PR author has agreed to Google's Contributor License Agreement labels Sep 22, 2016
@googlebot
Copy link

CLAs look good, thanks!

1 similar comment
@googlebot
Copy link

CLAs look good, thanks!

@googlebot googlebot added cla: yes PR author has agreed to Google's Contributor License Agreement and removed cla: no PR author must sign Google's Contributor License Agreement: https://opensource.google.com/docs/cla labels Sep 23, 2016
@@ -0,0 +1 @@
<template portalHost></template>
Copy link
Member

Choose a reason for hiding this comment

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

Add a wrapper div with the following:

<div aria-live="assertive" aria-atomic="true" role="alert">

Eventually this needs to use MdLiveAnnouncer, but this can suffice for now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added MdLiveAnnouncer, I have role="alert", but not the others currently.

@josephperrott
Copy link
Member Author

Tests added.
MdLiveAnnouncer is now used.

Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

LGTM aside from a last few nits

@@ -0,0 +1,3 @@
.button-label-input {
Copy link
Member

Choose a reason for hiding this comment

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

Prefix this with demo-

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.


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

expect(containerElement.getAttribute('role')).toBe('alert');
Copy link
Member

Choose a reason for hiding this comment

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

One new thing I want to start doing is adding a message to asserts. This one would be something like

expect(containerElement.getAttribute('role'))
    .toBe('alert', 'Expected snackbar container to have role="alert"');

I only found out you could do this last week, and it makes test failures much easier to quickly understand.

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

snackBarRef.dismiss();

expect(dismissed).toBeTruthy();
expect(overlayContainerElement.innerHTML.length).toBe(0);
Copy link
Member

Choose a reason for hiding this comment

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

expect(overlayContainer.innerHTML).toBe('') ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Switched over to checking child node count since that's what we are really trying to check.

@jelbourn
Copy link
Member

LGTM

@jelbourn jelbourn added pr: lgtm action: merge The PR is ready for merge by the caretaker and removed pr: needs review labels Sep 23, 2016
@kara kara merged commit a732e88 into angular:master Sep 23, 2016
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants