Skip to content
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
13 changes: 13 additions & 0 deletions ui-v2/src/components/ui/tag-badge-group.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,19 @@ describe("TagBadgeGroup", () => {
);
});

it("shows every tag when they fit, even if the counter is wider than the last tag", () => {
// the group sizes itself to its tags (120); the 70px counter would not
// fit next to the first tag, but it is not needed when both tags fit
restoreLayout = mockLayout(120, () => 70);
render(<TagBadgeGroup tags={["alpha", "beta"]} />);

expect(getVisibleTag("alpha")).toBeVisible();
expect(getVisibleTag("beta")).toBeVisible();
expect(
screen.queryByRole("button", { name: /more tags/i }),
).not.toBeInTheDocument();
});

it("measures duplicate tags independently", () => {
// 2 tags (120) + overflow (30) fit in 160
restoreLayout = mockLayout(160);
Expand Down
10 changes: 5 additions & 5 deletions ui-v2/src/components/ui/tag-badge-group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ export const TagBadgeGroup = ({
const widths = tags.map((_, i) => widthOf(tagRefs.current.get(i)));
let used = 0;
let count = 0;
// No early exit: a tag that does not fit next to the `+N` counter can
Comment thread
burrows99 marked this conversation as resolved.
Resolved
// still fit when it is the last tag and the counter is not shown.
for (let i = 0; i < cap; i++) {
used += widths[i];
const hasOverflow = i + 1 < tags.length;
const needed = used + widths[i] + (hasOverflow ? overflowWidth : 0);
if (needed > available) {
break;
if (used + (hasOverflow ? overflowWidth : 0) <= available) {
count = i + 1;
}
used += widths[i];
count = i + 1;
}
setVisibleCount(count);
setFullWidth(
Expand Down
Loading