-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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(list): add new '<mat-action-list>' #12415
Conversation
.gitignore
Outdated
@@ -41,4 +42,4 @@ testem.log | |||
|
|||
# schematics | |||
/src/lib/schematics/**/*.js | |||
/src/lib/schematics/**/*.map | |||
/src/lib/schematics/**/*.map |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you configure your IDE to always add a newline at the end of files? Looks like it removed the newline here.
src/demo-app/list/list-demo.html
Outdated
@@ -104,6 +104,15 @@ <h2>Nav lists</h2> | |||
</mat-nav-list> | |||
</div> | |||
|
|||
<div> | |||
<h2>Button lists</h2> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be "Action list"
src/demo-app/list/list-demo.html
Outdated
<h2>Button lists</h2> | ||
<mat-button-list> | ||
<button mat-list-item *ngFor="let link of links" (click)="onButtonClick(link.name)"> | ||
{{ link.name }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Omit space in braces
{{link.name}}
src/demo-app/list/list-demo.ts
Outdated
@@ -69,4 +69,8 @@ export class ListDemo { | |||
this.selectedOptions = values; | |||
this.modelChangeEventCount++; | |||
} | |||
|
|||
onButtonClick(msg: string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer to name methods for what they do rather than how they're called, e.g. alertItem(...)
(this doesn't really matter for demos, but I mention it just as an FYI)
src/lib/list/list.ts
Outdated
encapsulation: ViewEncapsulation.None, | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class MatButtonList extends _MatListMixinBase implements CanDisableRipple {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it looks like .mat-button-list
doesn't differ from .mat-list
for any styles or behavior, you should be able to just add mat-action-list
to the existing selector for MatList
without creating a new component
src/lib/list/list.ts
Outdated
selector: 'mat-button-list', | ||
exportAs: 'matButtonList', | ||
host: { | ||
'role': 'button list', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
role
corresponds to single value that defines the interaction pattern for an element:
https://www.w3.org/WAI/PF/HTML/wiki/RoleAttribute
There isn't any role that corresponds to a list of actions, so this isn't necessary here.
src/lib/list/list.ts
Outdated
|
||
@Component({ | ||
moduleId: module.id, | ||
selector: 'mat-button-list', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The selector for the new variant should be mat-action-list
src/lib/list/list.scss
Outdated
@@ -262,6 +262,22 @@ $mat-list-item-inset-divider-offset: 72px; | |||
} | |||
} | |||
|
|||
.mat-button-list { | |||
//remove the native button look and make is look like a list item | |||
button { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than using two levels of selector (.mat-button-list button
), it would be slightly better to use a single css class (.mat-action-list-item
) for this style. This will have a lower specificity and make it easier for users to customize the css.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We discussed and decided to go with the current nav list pattern.
@@ -92,7 +109,7 @@ export class MatListSubheaderCssMatStyler {} | |||
/** An item within a Material Design list. */ | |||
@Component({ | |||
moduleId: module.id, | |||
selector: 'mat-list-item, a[mat-list-item]', | |||
selector: 'mat-list-item, a[mat-list-item], button[mat-list-item]', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll need to add documentation for the new list variant to list.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/lib/list/_list-theme.scss
Outdated
@@ -27,7 +27,7 @@ | |||
} | |||
|
|||
.mat-list-option, | |||
.mat-nav-list .mat-list-item { | |||
.mat-nav-list .mat-button-list .mat-list-item { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This selector doesn't look correct. It'll target items inside a button list that is inside a nav list.
src/lib/list/_list-theme.scss
Outdated
@@ -46,7 +46,7 @@ | |||
} | |||
|
|||
// Default list | |||
.mat-list, .mat-nav-list, .mat-selection-list { | |||
.mat-list, .mat-nav-list, .mat-button-list, .mat-selection-list { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not something necessarily for this PR, but at some point we should add a class like mat-list-base
and use it for cases like this one. Since this selector has a few nested under it, the amount of CSS is going to increase a lot as we add more list types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, we should do that in a follow-up PR.
224eb2d
to
0f5d2ee
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please take a look again.
src/lib/list/list.spec.ts
Outdated
@@ -144,6 +145,14 @@ describe('MatList', () => { | |||
items.forEach(item => expect(item._isRippleDisabled()).toBe(true)); | |||
}); | |||
|
|||
it('action list should be created successfully', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the grammar wouldn't make sense here when testing with Karma.
This would make more sense:
it('should create an action list', () => {})
src/lib/list/list.spec.ts
Outdated
@Component({template: ` | ||
<mat-action-list> | ||
<button mat-list-item> | ||
Paprika |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indenting here should be 2 spaces instead of 4
.gitignore
Outdated
@@ -27,6 +27,7 @@ node_modules | |||
# IDEs | |||
/.idea | |||
/.vscode | |||
*.iml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where did this additional line come from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the ide file
src/demo-app/list/list-demo.html
Outdated
<div> | ||
<h2>Action list</h2> | ||
<mat-action-list> | ||
<button mat-list-item *ngFor="let link of links" (click)="alertItem(link.name)"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra whitespace character after mat-list-item
@@ -69,4 +69,8 @@ export class ListDemo { | |||
this.selectedOptions = values; | |||
this.modelChangeEventCount++; | |||
} | |||
|
|||
alertItem(msg: string) { | |||
alert(msg); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use a snack bar instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A snack bar will look nicer. It can be done later in my opinion. I am new to angular, so try to do small check in without taking too long to deal with merge conflict etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This app is only for our own development, so it doesn't really matter what the action does.
src/lib/list/list.md
Outdated
@@ -42,6 +42,20 @@ element in an `<mat-list-item>`. | |||
</mat-nav-list> | |||
``` | |||
|
|||
### Action lists | |||
|
|||
Use `mat-action-list` tags for action lists (i.e. lists that have button tags). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe rephrase this sentence to this?
A
<mat-action-list>
element is used for action lists (i.e. lists that have button tags.)
(This is based on the earlier section about navigation lists.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The navigation list is actually doing the same as what I have put in originally. And I feel "use xxx" is more clear than "xxx is used" here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would word this as
Use the `<mat-action-list>` element when each item in the list performs some _action_. Each item
in an action list is a `<button>` element.
<!-- example here -->
I think it would also be good to change the nav-list section similarly, but that can be done in another PR.
src/lib/list/list.md
Outdated
|
||
```html | ||
<mat-action-list> | ||
<button mat-list-item *ngFor="let link of links" (click)="alertItem(link.name)"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Extra whitespace character after
mat-list-item
- Show what the
alertItem
function does
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed the white space. Also removed the click part since it is not showing the key point here and may cause unnecessary confusion.
src/lib/list/list.scss
Outdated
@@ -262,6 +262,22 @@ $mat-list-item-inset-divider-offset: 72px; | |||
} | |||
} | |||
|
|||
mat-action-list { | |||
//remove the native button look and make is look like a list item |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: is
should be it
Hi @vivian-hu! This PR has merge conflicts due to recent upstream merges. |
src/lib/list/list.md
Outdated
@@ -42,6 +42,20 @@ element in an `<mat-list-item>`. | |||
</mat-nav-list> | |||
``` | |||
|
|||
### Action lists | |||
|
|||
Use `mat-action-list` tags for action lists (i.e. lists that have button tags). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would word this as
Use the `<mat-action-list>` element when each item in the list performs some _action_. Each item
in an action list is a `<button>` element.
<!-- example here -->
I think it would also be good to change the nav-list section similarly, but that can be done in another PR.
src/lib/list/list.md
Outdated
```html | ||
<mat-action-list> | ||
<button mat-list-item *ngFor="let link of links"> {{link.name}} </button> | ||
</mat-action-list> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would make the following changes:
<mat-action-list>
<button mat-list-item (click)="save()">Save</button>
<button mat-list-item (click)="undo()">Undo</button>
</mat-action-list>
- Getting rid of
ngFor
makes it a bit simpler - Adding a
(click)
handler shows how the action is performed
@@ -92,7 +92,7 @@ export class MatListSubheaderCssMatStyler {} | |||
/** An item within a Material Design list. */ | |||
@Component({ | |||
moduleId: module.id, | |||
selector: 'mat-list-item, a[mat-list-item]', | |||
selector: 'mat-list-item, a[mat-list-item], button[mat-list-item]', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One last thing that occurred to me just now- we should default all buttons with mat-list-item
to have type="button"
. By default, <button>
elements are type="submit"
, which you would never really want in an action list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add default type to button and also added unit testing to test it. Updated wording according to Jeremy's suggestion.
src/lib/list/list.spec.ts
Outdated
@@ -144,6 +146,30 @@ describe('MatList', () => { | |||
items.forEach(item => expect(item._isRippleDisabled()).toBe(true)); | |||
}); | |||
|
|||
it('should create an action list', () => { | |||
let fixture = TestBed.createComponent(ActionListWithoutType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer const
over let
whenever the variable isn't going to be assigned to something else
84b95c2
to
36e534c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed const vs. let.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Commit message should be
|
@@ -262,6 +262,22 @@ $mat-list-item-inset-divider-offset: 72px; | |||
} | |||
} | |||
|
|||
mat-action-list { | |||
//remove the native button look and make it look like a list item | |||
button { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this apply to all button
s for any .mat-list-item
not just the ones under a mat-action-list
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we talked, we added mat-action-list specifically for action list to make it more clear, so the idea is to let user use it under mat-action-list.
src/lib/list/list.ts
Outdated
|
||
// If no type attributed is specified for <button>, set it to "button". | ||
// If a type attribute is already specified, do nothing. | ||
let element: HTMLElement = this._getHostElement(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const
should be used here instead of let
since element
does not get reassigned.
src/lib/list/list.ts
Outdated
|
||
// If no type attributed is specified for <button>, set it to "button". | ||
// If a type attribute is already specified, do nothing. | ||
let element: HTMLElement = this._getHostElement(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since _getHostElement()
defines the return type of HTMLElement
, you don't need to define the type for the element
variable.
src/lib/list/list.ts
Outdated
// If no type attributed is specified for <button>, set it to "button". | ||
// If a type attribute is already specified, do nothing. | ||
let element: HTMLElement = this._getHostElement(); | ||
if (element.nodeName && element.nodeName.toLowerCase() === 'button' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could actually check tagName
. Since element is already a type of HtmlElement
, you shouldn't need to check if a tagName
is defined since it always will have tagName
by definition of the HtmlElement
interface.
Additionally, you can just set the attribute type
without performing a check beforehand.
if (element.tagName === 'BUTTON') {
element.setAttribute('type', element.getAttribute('type') || 'button');
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually prefer always doing nodeName
since it's guaranteed to be safe. It should probably be in the coding standards...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
more update based on Joey's feedback
@@ -262,6 +262,22 @@ $mat-list-item-inset-divider-offset: 72px; | |||
} | |||
} | |||
|
|||
mat-action-list { | |||
//remove the native button look and make it look like a list item | |||
button { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we talked, we added mat-action-list specifically for action list to make it more clear, so the idea is to let user use it under mat-action-list.
Hi @vivian-hu! This PR has merge conflicts due to recent upstream merges. |
simple list only in this check in
An action-list is a list where each list item is a native '<button>' element, meant to be used in cases where each list item has a single action with no sub-action, navigation or selection.
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
simple list only in this check in