Skip to content

Commit

Permalink
feat(chip): trailing remove icon can now be customized
Browse files Browse the repository at this point in the history
  • Loading branch information
vdegenne committed Dec 9, 2023
1 parent 2a4db32 commit 76883cd
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 14 deletions.
2 changes: 1 addition & 1 deletion chips/internal/_trailing-icon.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
width: var(--_icon-size);
}

[name="trailing-icon"]::slotted(md-icon) {
[name="remove-trailing-icon"]::slotted(md-icon) {
--md-icon-size: var(--_icon-size);
color: inherit;
}
Expand Down
4 changes: 2 additions & 2 deletions chips/internal/filter-chip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {renderRemoveButton} from './trailing-icons.js';
*/
export class FilterChip extends MultiActionChip {
@property({type: Boolean}) elevated = false;
@property({type: Boolean, attribute: 'has-trailing'}) hasTrailing = false;
@property({type: Boolean}) removable = false;
@property({type: Boolean, reflect: true}) selected = false;

/**
Expand Down Expand Up @@ -84,7 +84,7 @@ export class FilterChip extends MultiActionChip {
}

protected override renderTrailingAction(focusListener: EventListener) {
if (this.hasTrailing) {
if (this.removable) {
return renderRemoveButton({
focusListener,
ariaLabel: this.ariaLabelRemove,
Expand Down
9 changes: 0 additions & 9 deletions chips/internal/multi-action-chip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,6 @@ export abstract class MultiActionChip extends Chip {
protected abstract readonly primaryAction: HTMLElement | null;
protected abstract readonly trailingAction: HTMLElement | null;

/**
* Getter used to determine if the user provided a trailing icon or not.
*/
get hasSlottedTrailingIcon() {
const slot = this.shadowRoot.querySelector('slot[name="trailing-icon"]') as HTMLSlotElement;
// Default slot is not counted as one element.
return slot.assignedElements().length > 0;
}

constructor() {
super();
this.handleTrailingActionFocus = this.handleTrailingActionFocus.bind(this);
Expand Down
4 changes: 2 additions & 2 deletions chips/internal/trailing-icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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">
<svg viewBox="0 96 960 960" aria-hidden="true">
<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" />
Expand All @@ -46,7 +46,7 @@ export function renderRemoveButton({
}

function handleRemoveClick(this: MultiActionChip, event: Event) {
if (this.disabled || this.hasSlottedTrailingIcon) {
if (this.disabled) {
return;
}

Expand Down

0 comments on commit 76883cd

Please sign in to comment.