-
Notifications
You must be signed in to change notification settings - Fork 914
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(chip): trailing remove icon can now be customized #5263
feat(chip): trailing remove icon can now be customized #5263
Conversation
Also let's check in on the motivation for this change. Do we want to replace the remove button's icon with something else, like a trash can? Or do we want to replace remove functionality with something new, such as a dropdown icon? |
@asyncLiz It seems that the more general the better in this case, I see some cases where one developer would want to do something more than just removing or showing a dropdown icon (for instance showing an "info" icon that opens a small dialog to give more info about a special type of filter) |
I agree! Let's tackle that separately then, and scope this to just customizing the remove button's icon :) I'll update the pr title to reflect |
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.
omg I forgot to publish my comments... so sorry!
@asyncLiz Ok so if I understand you want to give the ability to change remove icon and later add another slot so users can insert anything at the end? <md-filter-chip
removable
>
<md-icon-button slot="trailing-icon">...</md-icon-button>
</md-filter-chip> will end up showing two different trailing elements, is that ok? Just to make sure we are on the same page, the modifications I provide allow this writing: <!-- show "remove" trailing icon button by default -->
<md-filter-chip
has-trailing
@remove=${/* executed when remove icon button clicked */}
></md-filter-chip>
<!-- user can change the default -->
<md-filter-chip
has-trailing
@remove=${/* won't get executed */}
>
<md-icon slot="trailing-icon">arrow_drop_down</md-icon>
</md-filter-chip> We can then allow users to insert what they want in the chip by providing a general |
I'm thinking that <!-- Only the new icon button shows, not a second one. `removable` has no effect -->
<md-filter-chip removable>
<md-icon-button slot="trailing-icon">...</md-icon-button>
</md-filter-chip>
<!-- Remove button shows with different icon -->
<md-filter-chip removable>
<md-icon slot="remove-trailing-icon">trash</md-icon>
</md-filter-chip>
<!-- Only the new icon button shows, custom remove trailing icon does not. -->
<md-filter-chip removable>
<md-icon slot="remove-trailing-icon">trash</md-icon>
<md-icon-button slot="trailing-icon">...</md-icon-button>
</md-filter-chip> |
That is correct, the remove event will not fire with an entirely new custom trailing-icon slot. It would fire with a |
@asyncLiz Last attempt. I don't want to bother I just studied the code thoroughly and tried different solutions, just making sure you fully understand this approach. <md-filter-chip
has-trailing
@trailing-click=${this.#openChipMenu}
>
<md-icon slot="trailing-icon">arrow_drop_down</md-icon>
<!-- default slot -->
<md-menu>...</md-menu>
</md-filter-chip> Another advantage for this syntax is all the focus-ring navigation logic you wrote still act as intended and do not need additional code. |
We use I'd prefer to keep I think an event like |
@asyncLiz Ok it's clear now, thanks for the heads-up. I'll complete this PR and probably leave the |
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.
Looking great! Just a couple nits
chips/internal/_trailing-icon.scss
Outdated
[name="trailing-icon"]::slotted(md-icon) { | ||
[name="remove-trailing-icon"]::slotted(md-icon) { | ||
--md-icon-size: var(--_icon-size); | ||
color: inherit; | ||
} |
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 should be able to remove all of this CSS by creating a wrapper <span class="trailing icon">
around the slot. Then it will re-use shared .icon
styles to size the icon:
.icon ::slotted(:first-child) {
font-size: var(--_icon-size);
height: var(--_icon-size);
width: var(--_icon-size);
}
color
inherits through slots, and <md-icon>
explicitly has color: inherit
so I don't think we need that declaration either.
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.
Nice, I just realize font-size
on md-icon
will size the icon to match this value, this is so perfect.
chips/internal/trailing-icons.ts
Outdated
@@ -34,7 +34,7 @@ export function renderRemoveButton({ | |||
@focus=${focusListener}> | |||
<md-focus-ring part="trailing-focus-ring"></md-focus-ring> | |||
<md-ripple ?disabled=${disabled}></md-ripple> | |||
<slot name="trailing-icon" class="trailing icon"> | |||
<slot name="remove-trailing-icon" class="trailing icon"> |
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 we move the .trailing.icon
to a wrapping <span>
element?
<span class="trailing icon">
<slot name="remove-trailing-icon">...</slot>
</span>
This will re-use the shared .icon
and .icon ::slotted()
styles and set things up for the next <slot name="trailing-icon">
.
chips/internal/trailing-icons.ts
Outdated
@@ -9,7 +9,7 @@ import '../../ripple/ripple.js'; | |||
|
|||
import {html, nothing} from 'lit'; | |||
|
|||
import {Chip} from './chip.js'; | |||
import {MultiActionChip} from './multi-action-chip.js'; |
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 can revert this change
<path | ||
d="m249 849-42-42 231-231-231-231 42-42 231 231 231-231 42 42-231 231 231 231-42 42-231-231-231 231Z" /> | ||
</svg> | ||
<span class="trailing icon"> |
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 change is 🤌
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.
\ o / I like how it reverted to just that
27d3541
into
material-components:main
I made a preliminary commit just to show the course it's taking.
A
slot
was inserted directly into therenderRemoveButton
method so everything works as intended with the keydown events and focus logic.Another advantage is that
md-input-chip
will also inherit this change so users can use a different remove trailing icon if they want.