Skip to content

fix: overflow badge width calculation uses marginInline shorthand #41

@javier-godoy

Description

@javier-godoy

Bug

In fc-badge-list.ts, the overflow badge width is computed as:

let overflowWidth = overflow.offsetWidth + parseInt(overflowStyle.marginInline);

getComputedStyle().marginInline is a shorthand property. In browsers that return both values (e.g. "4px 8px"), parseInt reads only the first token and discards the second, producing an incorrect total width. In other browsers the collapsed single-value form happens to work, so the bug is browser-dependent.

The same class of bug was already fixed for per-badge elements in commit 031522c by switching to marginInlineStart + marginInlineEnd:

let elementStyle = getComputedStyle(element);
let elementWidth = element.offsetWidth + parseInt(elementStyle.marginInlineStart) + parseInt(elementStyle.marginInlineEnd);

The equivalent fix was not applied to the overflow badge on line 168:

overflow.removeAttribute("hidden");
let overflowStyle = getComputedStyle(overflow);
let overflowWidth = overflow.offsetWidth + parseInt(overflowStyle.marginInline);
// Reset badges for calculations

Fix

let overflowWidth = overflow.offsetWidth + parseInt(overflowStyle.marginInlineStart) + parseInt(overflowStyle.marginInlineEnd);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Inbox (needs triage)

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions