Skip to content

Commit

Permalink
fix: limit tooltip size in inbox
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Onnikov <[email protected]>
  • Loading branch information
aonnikov committed Nov 23, 2024
1 parent 1095493 commit b1f6f9b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
11 changes: 11 additions & 0 deletions packages/ui/src/components/TooltipInstance.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
right: string
width: string
height: string
maxWidth: string
transform: string
visibility: string
classList: string
Expand All @@ -57,6 +58,7 @@
right: '',
width: '',
height: '',
maxWidth: '',
transform: '',
visibility: 'hidden',
classList: ''
Expand All @@ -71,6 +73,7 @@
right: '',
width: '',
height: '',
maxWidth: '',
transform: '',
visibility: 'hidden',
classList: ''
Expand All @@ -86,6 +89,7 @@
width: '',
height: '',
transform: '',
maxWidth: '',
visibility: 'visible',
classList: ''
}
Expand Down Expand Up @@ -140,6 +144,9 @@
else dir = 'top'
} else dir = $tooltip.direction
const left = rectAnchor.x + rectAnchor.width / 2
const maxWidth = Math.min(left, docWidth - left)
if (dir === 'right') {
options.top = rectAnchor.y + rectAnchor.height / 2 + 'px'
options.left = `calc(${rectAnchor.right}px + .75rem)`
Expand All @@ -151,10 +158,12 @@
} else if (dir === 'bottom') {
options.top = `calc(${rectAnchor.bottom}px + .5rem)`
options.left = rectAnchor.x + rectAnchor.width / 2 + 'px'
options.maxWidth = `calc(${maxWidth * 2}px - 1.5rem)`
options.transform = 'translateX(-50%)'
} else if (dir === 'top') {
options.bottom = `calc(${docHeight - rectAnchor.y}px + .75rem)`
options.left = rectAnchor.x + rectAnchor.width / 2 + 'px'
options.maxWidth = `calc(${maxWidth * 2}px - 1.5rem)`
options.transform = 'translateX(-50%)'
}
}
Expand Down Expand Up @@ -183,6 +192,7 @@
right: '',
width: '',
height: '',
maxWidth: '',
visibility: 'visible',
transform: '',
classList: ''
Expand Down Expand Up @@ -356,6 +366,7 @@
style:right={options.right}
style:width={options.width}
style:height={options.height}
style:max-width={options.maxWidth}
style:transform={options.transform}
style:z-index={($modals.findIndex((t) => t.type === 'tooltip') ?? 1) + 10000}
>
Expand Down
11 changes: 10 additions & 1 deletion plugins/activity-resources/src/components/BasePreview.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
const client = getClient()
const limit = 300
const tooltipLimit = 512
let isActionsOpened = false
let person: WithLookup<Person> | undefined = undefined
Expand Down Expand Up @@ -83,6 +84,14 @@
} else {
tooltipLabel = core.string.System
}
function getTooltipText (markup: string): string {
const text = markupToText(markup)
if (text.length > tooltipLimit) {
return text.substring(0, tooltipLimit) + '...'
}
return text
}
</script>

<!-- svelte-ignore a11y-no-static-element-interactions -->
Expand Down Expand Up @@ -138,7 +147,7 @@
<span
class="textContent overflow-label font-normal"
class:contentOnly={type === 'content-only'}
use:tooltip={{ label: text ? getEmbeddedLabel(markupToText(text)) : intlLabel }}
use:tooltip={{ label: text ? getEmbeddedLabel(getTooltipText(text)) : intlLabel }}
>
{#if intlLabel}
<Label label={intlLabel} />
Expand Down

0 comments on commit b1f6f9b

Please sign in to comment.