Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui): handle long text in BuilderSelect #706

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/ui/src/builder/BuilderSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
<i v-if="!hideIcons" class="material-symbols-outlined">{{
currentIcon
}}</i>
<div class="BuilderSelect__trigger__label">{{ currentLabel }}</div>
<div
class="BuilderSelect__trigger__label"
data-writer-tooltip-strategy="overflow"
:data-writer-tooltip="currentLabel"
>
{{ currentLabel }}
</div>
<div class="BuilderSelect__trigger__arrow">
<i class="material-symbols-outlined">{{ expandIcon }}</i>
</div>
Expand Down Expand Up @@ -141,6 +147,7 @@ function onSelect(value: string) {
overflow: hidden;
flex-grow: 1;
text-align: left;
white-space: nowrap;
}
.BuilderSelect__trigger__arrow {
border: none;
Expand Down
11 changes: 10 additions & 1 deletion src/ui/src/builder/BuilderTooltip.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ async function setUpAndShowTooltip() {
const gapPx = trackedElement.dataset.writerTooltipGap
? parseInt(trackedElement.dataset.writerTooltipGap)
: DEFAULT_GAP_PX;
isActive.value = true;
isActive.value = canBeActive(trackedElement);
if (!isActive.value) return;
await nextTick();
const { x, y, width, height } = trackedElement.getBoundingClientRect();
const { width: tooltipWidth, height: tooltipHeight } =
Expand All @@ -69,6 +70,12 @@ async function setUpAndShowTooltip() {
}
}

function canBeActive(el: HTMLElement) {
const strategy = el.getAttribute("data-writer-tooltip-strategy");
if (strategy === "overflow") return el.scrollWidth > el.clientWidth;
return true;
}

function handleMouseover(ev: MouseEvent) {
const el = ev.target as HTMLElement;

Expand Down Expand Up @@ -98,6 +105,7 @@ async function confirmTooltip(el: HTMLElement) {
attributeFilter: [
"data-writer-tooltip",
"data-writer-tooltip-placement",
"data-writer-tooltip-strategy",
],
});
setUpAndShowTooltip();
Expand Down Expand Up @@ -131,6 +139,7 @@ onUnmounted(() => {
display: content;
max-width: 260px;
filter: drop-shadow(0px 0px 12px rgba(0, 0, 0, 0.16));
word-break: break-all;
}

.arrow {
Expand Down
7 changes: 6 additions & 1 deletion src/ui/src/wds/WdsDropdownMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
<i v-if="!hideIcons" class="material-symbols-outlined">{{
getOptionIcon(option)
}}</i>
<div class="WdsDropdownMenu__item__label">
<div
class="WdsDropdownMenu__item__label"
:data-writer-tooltip="option.label"
data-writer-tooltip-strategy="overflow"
>
{{ option.label }}
</div>
<i
Expand Down Expand Up @@ -138,6 +142,7 @@ watch(searchTerm, () => emits("search", searchTerm.value));
}
.WdsDropdownMenu__item__label {
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
text-align: left;
}
Expand Down
Loading