Skip to content

Commit b30d09e

Browse files
committed
add hasSlottedTrailingIcon
1 parent 9ff29ac commit b30d09e

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

chips/internal/filter-chip.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {renderRemoveButton} from './trailing-icons.js';
2222
*/
2323
export class FilterChip extends MultiActionChip {
2424
@property({type: Boolean}) elevated = false;
25-
@property({type: Boolean}) removable = false;
25+
@property({type: Boolean, attribute: 'has-trailing'}) hasTrailing = false;
2626
@property({type: Boolean, reflect: true}) selected = false;
2727

2828
protected get primaryId() {
@@ -39,7 +39,7 @@ export class FilterChip extends MultiActionChip {
3939
...super.getContainerClasses(),
4040
elevated: this.elevated,
4141
selected: this.selected,
42-
'has-trailing': this.removable,
42+
'has-trailing': this.hasTrailing,
4343
};
4444
}
4545

@@ -72,7 +72,7 @@ export class FilterChip extends MultiActionChip {
7272
}
7373

7474
protected override renderTrailingAction(focusListener: EventListener) {
75-
if (this.removable) {
75+
if (this.hasTrailing) {
7676
return renderRemoveButton({
7777
focusListener,
7878
ariaLabel: this.ariaLabelRemove,

chips/internal/multi-action-chip.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ export abstract class MultiActionChip extends Chip {
4242
protected abstract readonly primaryAction: HTMLElement | null;
4343
protected abstract readonly trailingAction: HTMLElement | null;
4444

45+
/**
46+
* Getter used to determine if the user provided a trailing icon or not.
47+
*/
48+
get hasSlottedTrailingIcon() {
49+
const slot = this.shadowRoot.querySelector('slot[name="trailing-icon"]') as HTMLSlotElement;
50+
// Default slot is not counted as one element.
51+
return slot.assignedElements().length > 0;
52+
}
53+
4554
constructor() {
4655
super();
4756
this.handleTrailingActionFocus = this.handleTrailingActionFocus.bind(this);

chips/internal/trailing-icons.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import '../../ripple/ripple.js';
99

1010
import {html, nothing} from 'lit';
1111

12-
import {Chip} from './chip.js';
12+
import {MultiActionChip} from './multi-action-chip.js';
1313

1414
interface RemoveButtonProperties {
1515
ariaLabel: string;
@@ -45,8 +45,8 @@ export function renderRemoveButton({
4545
`;
4646
}
4747

48-
function handleRemoveClick(this: Chip, event: Event) {
49-
if (this.disabled) {
48+
function handleRemoveClick(this: MultiActionChip, event: Event) {
49+
if (this.disabled || this.hasSlottedTrailingIcon) {
5050
return;
5151
}
5252

0 commit comments

Comments
 (0)