Skip to content

Commit e18d793

Browse files
NguyenThuyLanLan Nguyen ThuyiOvergaard
authored
fix(uui-card): text overflow when user name is too long (#1036)
* fix issue text overflow when user name is too long * add ellipsis at the end of name * fix overflow for content card and block card * fix(uui-card-content-node): allow text to overflow anywhere just like the other cards * fix: allow string slots --------- Co-authored-by: Lan Nguyen Thuy <[email protected]> Co-authored-by: Jacob Overgaard <[email protected]>
1 parent 6a1366e commit e18d793

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

packages/uui-card-block-type/lib/uui-card-block-type.element.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ export class UUICardBlockTypeElement extends UUICardElement {
9696
#renderContent() {
9797
return html`
9898
<div id="content">
99-
<span id="name">${this.name}</span>
100-
<small>${this.description}<slot name="description"></slot></small>
99+
<span title="${this.name}" id="name">${this.name}</span>
100+
<small title="${this.description}">${this.description}<slot name="description"></slot></small>
101101
</div></div>
102102
`;
103103
}
@@ -176,6 +176,15 @@ export class UUICardBlockTypeElement extends UUICardElement {
176176
#open-part:hover #name {
177177
text-decoration: underline;
178178
}
179+
#open-part #name,
180+
#open-part small {
181+
display: -webkit-box;
182+
-webkit-line-clamp: 1;
183+
-webkit-box-orient: vertical;
184+
overflow: hidden;
185+
text-overflow: ellipsis;
186+
overflow-wrap: anywhere;
187+
}
179188
180189
:host([image]:not([image=''])) #open-part {
181190
transition: opacity 0.5s 0.5s;

packages/uui-card-content-node/lib/uui-card-content-node.element.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ export class UUICardContentNodeElement extends UUICardElement {
7676
? this._renderFallbackIcon()
7777
: ''}
7878
</span>
79-
<div id="name">${this.name}<slot name="name"></slot></div>
79+
<div title="${this.name}" id="name">
80+
${this.name}<slot name="name"></slot>
81+
</div>
8082
</span>
8183
${this.renderDetail()}
8284
</span>
@@ -173,6 +175,15 @@ export class UUICardContentNodeElement extends UUICardElement {
173175
padding: var(--uui-size-space-4) var(--uui-size-space-5);
174176
}
175177
178+
#open-part #name {
179+
display: -webkit-box;
180+
-webkit-line-clamp: 2;
181+
-webkit-box-orient: vertical;
182+
overflow: hidden;
183+
text-overflow: ellipsis;
184+
overflow-wrap: anywhere;
185+
}
186+
176187
#content {
177188
align-self: stretch;
178189
display: flex;

packages/uui-card-user/lib/uui-card-user.element.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class UUICardUserElement extends UUICardElement {
7676
name="avatar"
7777
class="avatar"
7878
@slotchange=${this._avatarSlotChanged}></slot>
79-
<span>${this.name}</span>
79+
<span title="${this.name}">${this.name}</span>
8080
<slot></slot>
8181
</div>`;
8282
}
@@ -159,12 +159,19 @@ export class UUICardUserElement extends UUICardElement {
159159
position: relative;
160160
align-items: center;
161161
margin: 0 0 3px 0;
162+
height: 100%;
162163
}
163164
164165
#content > span {
166+
display: -webkit-box;
167+
-webkit-line-clamp: 2;
168+
-webkit-box-orient: vertical;
169+
overflow: hidden;
170+
text-overflow: ellipsis;
165171
vertical-align: center;
166172
margin-top: 3px;
167173
font-weight: 700;
174+
overflow-wrap: anywhere;
168175
}
169176
170177
.avatar {

storyhelpers/render-slots.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ function renderSlots(param: TemplateResult[] | Args) {
3434
// Join slots with consistent formatting; no extra line breaks between them
3535
const spacing = ' ';
3636

37-
const stringSlots = validSlots.map(slot => slot.strings[0]);
37+
const stringSlots = validSlots.map(slot =>
38+
typeof slot === 'string' ? slot : slot.strings?.[0] ?? '',
39+
);
3840
const stringSlotsJoined = stringSlots.join('\n');
3941
const stringSlotsJoinedWithSpacing = stringSlotsJoined
4042
.split('\n')

0 commit comments

Comments
 (0)