-
Notifications
You must be signed in to change notification settings - Fork 6.8k
feat(material/chips): add (optional) edit icon to input chips #31041
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
base: main
Are you sure you want to change the base?
Conversation
Deployed dev-app for fe91543 to: https://ng-dev-previews-comp--pr-angular-components-31041-dev-jgj91wpx.web.app Note: As new commits are pushed to this pull request, this link is updated after the preview is rebuilt. |
c0b7505
to
0dfcea0
Compare
4960510
to
809e1e8
Compare
src/material/chips/chip-row.html
Outdated
class="mdc-evolution-chip__cell mdc-evolution-chip__cell--primary" | ||
role="gridcell"> | ||
<ng-content select="[matChipEdit]"></ng-content> | ||
</span> |
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.
nit: formatting appears to be off 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.
Done.
if ((event.keyCode === ENTER || event.keyCode === SPACE) && !this.disabled) { | ||
event.stopPropagation(); | ||
event.preventDefault(); | ||
this._parentChip._edit(); |
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 appears to allow editing even if the chip isn't marked as editable.
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.
That's correct. Editable controls the double-click and focus-enter, the button logic is independent.
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 suspect that may be confusing for developers using the component since the only way left to conditionally disable editing is by completely removing the edit icon.
selector: '[matChipEdit]', | ||
host: { | ||
'class': | ||
'mat-mdc-chip-edit mat-mdc-chip-avatar mat-focus-indicator ' + |
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 shouldn't reuse the avatar class here since this isn't the avatar.
- The focus indicator class already comes from whatever is used as the edit trigger (e.g.
matButton
).
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.
Yeah, let me clean up the avatar usage. I added the leading-action concept later and think makes sense to keep them distinct all the way through now.
* | ||
* ``` | ||
* <mat-chip> | ||
* <button matChipEdit aria-label="Edit"> |
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.
Should the component show matIconButton
?
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 don't in the demo's and actually adding it breaks the styling, so don't want to put in example here. Something to clean up later perhaps though.
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.
Ah I see. I assumed the demo was an icon button because of the ripple.
src/material/chips/chip-row.ts
Outdated
@@ -107,6 +108,11 @@ export class MatChipRow extends MatChip implements AfterViewInit { | |||
}); | |||
} | |||
|
|||
/** Returns whether the chip has a leading icon. */ | |||
_hasLeadingIcon() { |
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 one can be made protected so it's not exposed as a public API.
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.
@@ -107,6 +108,11 @@ export class MatChipRow extends MatChip implements AfterViewInit { | |||
}); | |||
} | |||
|
|||
/** Returns whether the chip has a leading icon. */ | |||
_hasLeadingIcon() { | |||
return !this._isEditing && !!(this.editIcon || this.leadingIcon); |
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.
Won't this end up hiding the avatar if the chip is being edited?
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.
That was intentional, but I'm not actually not sure if that logic was omitted as no demo cases for editable chips with avatar or intentionally kept visibile (unlike remove icon). But that can be handled seperately, so I'll pull this out.
@@ -158,7 +172,7 @@ export class MatChipRow extends MatChip implements AfterViewInit { | |||
afterNextRender( | |||
() => { | |||
this._getEditInput().initialize(value); | |||
this._editStartPending = false; | |||
setTimeout(() => this._ngZone.run(() => (this._editStartPending = false))); |
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.
Why do we need a timeout 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'll add a comment. When using the edit icon, need to have this timeout as otherwise subsequent blur will cancel the edit action.
b5951a7
to
3dbe36d
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.
Actually I also realized that we should add a live example for the docs site. The examples live under components-examples
.
* | ||
* ``` | ||
* <mat-chip> | ||
* <button matChipEdit aria-label="Edit"> |
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.
Ah I see. I assumed the demo was an icon button because of the ripple.
if ((event.keyCode === ENTER || event.keyCode === SPACE) && !this.disabled) { | ||
event.stopPropagation(); | ||
event.preventDefault(); | ||
this._parentChip._edit(); |
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 suspect that may be confusing for developers using the component since the only way left to conditionally disable editing is by completely removing the edit icon.
Adds an optional edit icon to input chips to allow for better discoverability of editable chips over existing double-click and focus-enter to edit behavior.
The edit icon introduces concept of a leading action with an icon button similar to trailing action used for delete icon button. This can be combined with the existing avatar icon for a chip. The editable flag is preserved but is independent of the edit icon, allowing for both existing and new behavior or either one.
Updated chip demo to add option to show avatar and/or edit icon.