Skip to content

Tag tooltips: the overflow check measures the wrong box, so tooltips are both missed and added unnecessarily #487

Description

@gnbm

What happens

With showValueAsTags: true, a selected tag gets a tooltip only if its label is judged to overflow. That judgement is made against the wrong element and the wrong font, so:

  • tags that visibly truncate can end up without a tooltip;
  • tags that fit comfortably can end up with one.

Why

setValueText() measures the label before the tag markup exists:

const valueTooltipForTags = Utils.willTextOverflow($valueText.parentElement, label)
  ? this.getTooltipAttrText(label, false, true) : '';

$valueText is .vscomp-value, so the container passed in is .vscomp-toggle-button, and willTextOverflow() compares the measured text width against that element's clientWidth, using that element's computed font. Neither matches what the text actually gets:

Compared against What the tag text really has
Width .vscomp-toggle-button clientWidth minus the button's padding (4px 22px 0 10px), the tag's border + padding + margin (~17px) and the 24px clear button — roughly 73px less
Font size inherited 14px from .vscomp-wrapper .vscomp-value-tag renders at 12px, so the measurement runs ~17% wide

The two errors push in opposite directions and do not reliably cancel.

Suggested fix

The check does not need an off-screen node at all.

  • The rendered tags are already collected into this.$valueTags immediately after the innerHTML write.
  • setValueTagAttr() already iterates every one of them.
  • DomUtils.hasEllipsis() (scrollWidth > offsetWidth) already exists, and is already used for the non-tag value text.

Doing the check there measures the real rendered box, so both inaccuracies disappear, and it replaces one forced synchronous layout per tag with a single batched read pass. Utils.willTextOverflow() and the shared measurer node can then be removed.

One constraint: read every tag first, then write the tooltips, so the loop does not interleave reads and writes and reintroduce the layout thrash.

Impact

More tags will carry tooltips than today. That is the corrected behaviour rather than a regression, but it is a visible change and worth a line in the release notes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions