diff --git a/chips/lib/_shared.scss b/chips/lib/_shared.scss index 070018bccd..ea44982fcb 100644 --- a/chips/lib/_shared.scss +++ b/chips/lib/_shared.scss @@ -75,17 +75,16 @@ border: none; border-radius: inherit; display: flex; + gap: 8px; outline: none; padding: 0; + position: relative; text-decoration: none; } - .action:first-of-type { + .primary.action { padding-inline-start: 8px; - } - - .action:last-of-type { - padding-inline-end: 8px; + padding-inline-end: 16px; } .touch { @@ -131,7 +130,6 @@ display: flex; font: var(--_label-text-type); height: 100%; - padding: 0 8px; text-overflow: ellipsis; user-select: none; white-space: nowrap; diff --git a/chips/lib/_trailing-icon.scss b/chips/lib/_trailing-icon.scss index 5a5ac8d9ea..2ea3ff7976 100644 --- a/chips/lib/_trailing-icon.scss +++ b/chips/lib/_trailing-icon.scss @@ -3,7 +3,40 @@ // SPDX-License-Identifier: Apache-2.0 // +// go/keep-sorted start +@use '../../focus/focus-ring'; +// go/keep-sorted end + @mixin styles() { + .trailing.action { + display: flex; + padding: 0 8px; + + // Note: the trailing action's shape only follows the trailing end of the + // chip. For example, if the leading end is rounded, but the trailing is end + // squared, then the focus ring will be squared (not rounded+squared). + @include focus-ring.theme( + ( + 'shape-start-start': var(--_container-shape-start-end), + 'shape-end-start': var(--_container-shape-end-end), + 'shape-end-end': var(--_container-shape-end-end), + 'shape-start-end': var(--_container-shape-start-end), + 'offset': -2px, + ) + ); + } + + .trailing.action md-ripple { + height: calc(4 / 3 * var(--_icon-size)); // 24px default + inset: 50% 0 0 50%; + transform: translateX(-50%) translateY(-50%); + width: calc(4 / 3 * var(--_icon-size)); // 24px default + } + + :has(.trailing.action) .primary.action { + padding-inline-end: 0; + } + .trailing .icon { color: var(--_trailing-icon-color); } diff --git a/chips/lib/assist-chip.ts b/chips/lib/assist-chip.ts index ecf3ab111a..dbea3c4575 100644 --- a/chips/lib/assist-chip.ts +++ b/chips/lib/assist-chip.ts @@ -44,7 +44,7 @@ export class AssistChip extends Chip { const {ariaLabel} = this as ARIAMixinStrict; if (this.href) { return html` - ${ripple} ${this.renderPrimaryAction()} - ${this.renderTrailingAction()} + ${this.renderTrailingAction?.() || nothing} `; } @@ -75,9 +75,7 @@ export abstract class Chip extends LitElement { protected abstract renderPrimaryAction(): TemplateResult; - protected renderTrailingAction(): TemplateResult|typeof nothing { - return nothing; - } + protected renderTrailingAction?(): TemplateResult|typeof nothing; protected renderOutline() { return html``; diff --git a/chips/lib/filter-chip.ts b/chips/lib/filter-chip.ts index ed0262a331..97487abeb2 100644 --- a/chips/lib/filter-chip.ts +++ b/chips/lib/filter-chip.ts @@ -13,12 +13,14 @@ import {ripple} from '../../ripple/directive.js'; import {ARIAMixinStrict} from '../../types/aria.js'; import {Chip} from './chip.js'; +import {renderRemoveButton} from './trailing-actions.js'; /** * A filter chip component. */ export class FilterChip extends Chip { @property({type: Boolean}) elevated = false; + @property({type: Boolean}) removable = false; @property({type: Boolean}) selected = false; protected get focusFor() { @@ -55,7 +57,7 @@ export class FilterChip extends Chip { protected override renderPrimaryAction() { const {ariaLabel} = this as ARIAMixinStrict; return html` - + `; +} + +function handleRemoveClick(this: Chip, event: Event) { + if (this.disabled) { + return; + } + + event.stopPropagation(); + const preventDefault = !this.dispatchEvent(new Event('remove')); + if (preventDefault) { + return; + } + + this.remove(); +}