discourse/app/assets/stylesheets/common/components/autocomplete.scss
Kelv 3352cec1bb
FIX: truncate long names for autocomplete results (#34479)
The current way we try to style text spans that are too long is to apply
the custom style `ellipsis` on the `a` element that wraps around text
spans for each autocomplete item. However, this is being positioned with
`flex` which does not apply that styling well on child elements.

We need to apply it directly on text spans and orient them with
`inline`/`inline-block`. As some of these autocomplete items have more
than 1 span element in the same line, we use a wrapper `.text-content`
as the target selector for this `ellipsis` styling.

#### Current:
<img width="524" height="276" alt="current"
src="https://github.com/user-attachments/assets/6f988106-8ac4-431c-bf97-e9f4e52643ef"
/>

#### Expected:
Older Autocomplete:
<img width="542" height="321" alt="jquery-autocomplete"
src="https://github.com/user-attachments/assets/da0bcc92-3916-4131-930a-65e8e844d3bc"
/>

Floatkit Autocomplete:


https://github.com/user-attachments/assets/0a999d37-2486-4939-8def-f0716841a953
2025-08-22 15:30:03 +08:00

123 lines
2.3 KiB
SCSS
Vendored

@use "lib/viewport";
.autocomplete {
z-index: z("composer", "dropdown") + 1;
max-width: 370px;
min-width: 300px;
background-color: var(--secondary);
border: 1px solid var(--primary-low);
box-shadow: var(--shadow-dropdown);
border-radius: 8px;
@include viewport.from(sm) {
max-width: 600px;
}
ul {
list-style: none;
padding: 0;
margin: 0;
li {
&:first-of-type a {
border-top-left-radius: 8px;
border-top-right-radius: 8px;
}
&:last-of-type a {
border-bottom-left-radius: 8px;
border-bottom-right-radius: 8px;
}
a {
align-items: center;
color: var(--primary);
display: flex;
gap: 0.25em;
padding: 0.3em 1em;
@include hover {
background-color: var(--d-hover);
text-decoration: none;
}
&.selected {
background-color: var(--d-selected);
}
.avatar {
margin-right: 0.25em;
}
.name {
display: contents;
font-size: var(--font-down-1);
color: var(--primary-high);
}
.user-status-message {
display: flex;
align-items: center;
gap: 0.25em;
.user-status-message-description {
@include ellipsis;
font-size: var(--font-down-2);
color: var(--primary-high);
margin: 0;
}
}
.relative-date {
font-size: var(--font-down-3);
}
.text-content {
@include ellipsis;
display: inline-block;
max-width: 100%;
vertical-align: top;
.username,
.name {
display: inline;
}
}
.d-icon + .text-content {
max-width: calc(100% - 1em);
}
}
.d-icon-users {
color: var(--primary-medium);
padding: 0 2px;
}
}
}
&.ac-user {
li a {
padding: 0.5em 1em;
.text-content {
max-width: calc(100% - 24px); // 24px is for `tiny` avatar width
}
}
.emoji {
height: 0.75em;
width: 0.75em;
}
}
&.ac-emoji {
li:last-of-type a {
color: var(--primary-high);
}
.emoji {
margin-right: 0.25em;
}
}
}