Skip to content

Commit

Permalink
fix(chips): add truncation support
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 649094591
  • Loading branch information
material-web-copybara authored and copybara-github committed Jul 3, 2024
1 parent d23ea84 commit 713f0a8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
17 changes: 15 additions & 2 deletions chips/internal/_shared.scss
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@
}

.primary.action {
// Set a min-width on the primary action so that trailing actions remain
// inside the chip as the chip is resized.
min-width: 0;
padding-inline-start: var(--_leading-space);
padding-inline-end: var(--_trailing-space);
}
Expand Down Expand Up @@ -151,11 +154,21 @@
display: flex;
font-family: var(--_label-text-font);
font-size: var(--_label-text-size);
line-height: var(--_label-text-line-height);
font-weight: var(--_label-text-weight);
height: 100%;
text-overflow: ellipsis;
line-height: var(--_label-text-line-height);
overflow: hidden;
user-select: none;
}

// An inner span is needed to truncate the label, since elements with a flex
// display do not support the text-overflow property. The outer wrapper .label
// needs to be a flex display to correctly set the element's baseline,
// supporting external elements aligning to the baseline of the chip's text
// instead of its edges or icons.
.label-text {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}

Expand Down
4 changes: 3 additions & 1 deletion chips/internal/chip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ export abstract class Chip extends chipBaseClass {
<span class="leading icon" aria-hidden="true">
${this.renderLeadingIcon()}
</span>
<span class="label">${this.label}</span>
<span class="label">
<span class="label-text">${this.label}</span>
</span>
<span class="touch"></span>
`;
}
Expand Down

0 comments on commit 713f0a8

Please sign in to comment.