Skip to content

Commit 713f0a8

Browse files
fix(chips): add truncation support
PiperOrigin-RevId: 649094591
1 parent d23ea84 commit 713f0a8

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

chips/internal/_shared.scss

+15-2
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@
9696
}
9797

9898
.primary.action {
99+
// Set a min-width on the primary action so that trailing actions remain
100+
// inside the chip as the chip is resized.
101+
min-width: 0;
99102
padding-inline-start: var(--_leading-space);
100103
padding-inline-end: var(--_trailing-space);
101104
}
@@ -151,11 +154,21 @@
151154
display: flex;
152155
font-family: var(--_label-text-font);
153156
font-size: var(--_label-text-size);
154-
line-height: var(--_label-text-line-height);
155157
font-weight: var(--_label-text-weight);
156158
height: 100%;
157-
text-overflow: ellipsis;
159+
line-height: var(--_label-text-line-height);
160+
overflow: hidden;
158161
user-select: none;
162+
}
163+
164+
// An inner span is needed to truncate the label, since elements with a flex
165+
// display do not support the text-overflow property. The outer wrapper .label
166+
// needs to be a flex display to correctly set the element's baseline,
167+
// supporting external elements aligning to the baseline of the chip's text
168+
// instead of its edges or icons.
169+
.label-text {
170+
overflow: hidden;
171+
text-overflow: ellipsis;
159172
white-space: nowrap;
160173
}
161174

chips/internal/chip.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ export abstract class Chip extends chipBaseClass {
128128
<span class="leading icon" aria-hidden="true">
129129
${this.renderLeadingIcon()}
130130
</span>
131-
<span class="label">${this.label}</span>
131+
<span class="label">
132+
<span class="label-text">${this.label}</span>
133+
</span>
132134
<span class="touch"></span>
133135
`;
134136
}

0 commit comments

Comments
 (0)