Skip to content

fix!: filtertag overflow via resizeobserver (#949)#951

Merged
NoopDog merged 3 commits into
mainfrom
fran/949-filtertag-overflow-resize-observer
Jun 5, 2026
Merged

fix!: filtertag overflow via resizeobserver (#949)#951
NoopDog merged 3 commits into
mainfrom
fran/949-filtertag-overflow-resize-observer

Conversation

@frano-m

@frano-m frano-m commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #949.

Replaces the ref-during-render overflow check in FilterTag with a ResizeObserver-based measurement inside a dedicated useTooltipTitle hook. The hook owns the ref + the derived overflow state and returns { ref, title } — the title is the label when truncated, null otherwise.

Why

The original implementation read tagRef.current synchronously during render to compare offsetWidth vs scrollWidth. Two problems:

  • On first render, tagRef.current is null, so isOverflowed was always false until something else triggered a re-render.
  • The computed value wasn't reactive — the component never re-rendered when overflow state actually changed (window resize, label change, font-load reflow).

A ResizeObserver on the .MuiChip-label element fixes both: the boolean now updates reactively, and the tooltip stays accurate across layout changes.

What changed

  • New src/components/Filter/components/FilterTag/hooks/UseTooltipTitle/ (hook.ts + types.ts) — owns ref + effect + state.
  • filterTag.tsx slimmed down to JSX + a single useTooltipTitle(label) call.

Test plan

  • Filter a long-value column → tag truncates with ellipsis → hover shows tooltip with full text.
  • Filter a short value that fits → no tooltip.
  • Resize panel so a long tag stops truncating → tooltip disappears (and vice versa).
  • CI green.

Rebase note

Branched off main, which does not yet contain the react-hooks/refs per-site suppression added by #950 (the PR for #941). Once #950 lands, this PR needs a rebase + the (now-redundant) suppression block can be dropped — that's the "remove the per-site suppression from #941" acceptance criterion in #949. Draft until that's done.

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings June 5, 2026 00:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates FilterTag’s tooltip behavior so the tooltip title is derived from a reactive, post-render measurement rather than reading ref.current during render. It introduces a dedicated useTooltipTitle hook that owns the ref and tracks whether the chip label is truncated.

Changes:

  • Added useTooltipTitle hook to observe .MuiChip-label truncation via ResizeObserver and return { ref, title }.
  • Refactored FilterTag to use the new hook and remove ref reads during render.
  • Introduced a small type definition for the hook return shape.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/components/Filter/components/FilterTag/hooks/UseTooltipTitle/types.ts Adds the UseTooltipTitle return type for the new hook.
src/components/Filter/components/FilterTag/hooks/UseTooltipTitle/hook.ts Implements the ResizeObserver-based truncation/tooltip-title logic.
src/components/Filter/components/FilterTag/filterTag.tsx Replaces render-time overflow checks with useTooltipTitle(label) usage.

Comment thread src/components/Filter/components/FilterTag/filterTag.tsx Outdated
frano-m and others added 2 commits June 5, 2026 10:35
Replaces the ref-during-render measurement (which only computed
isOverflowed once mid-render with a null ref, then never reacted
to layout changes) with a ResizeObserver inside a dedicated
useTooltipTitle hook that returns the chip ref and the tooltip
title together.

The tooltip now stays accurate across container resizes, font
loads, and label changes. Hook lives at
src/components/Filter/components/FilterTag/hooks/UseTooltipTitle/
following the existing per-folder hook convention.

Companion to #941 (PR #950) — once that lands the
react-hooks/refs suppression added there is no longer needed and
will be dropped on rebase.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Audit while landing #949 revealed superseded was always passed as
false from every call site (filters.tsx, FilterTag/utils.ts,
stories args, filterTags.stories.tsx) and the SupersededTag
styled component was therefore never rendered.

Strips the prop from CategoryTag, FilterTag, FilterTags, and the
two stories files. Deletes filterTag.styles.ts (only contained
SupersededTag).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 5, 2026 00:36
@frano-m frano-m force-pushed the fran/949-filtertag-overflow-resize-observer branch from 581eef5 to 633b18f Compare June 5, 2026 00:36
@frano-m frano-m marked this pull request as ready for review June 5, 2026 00:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

Comment thread src/common/entities.ts
Comment thread src/components/Filter/components/FilterTag/filterTag.tsx
@frano-m frano-m changed the title fix: filtertag overflow via resizeobserver (#949) fix!: filtertag overflow via resizeobserver (#949) Jun 5, 2026
Adds Jest/RTL coverage for the new FilterTag tooltip behaviour:

- Suppresses the tooltip when offsetWidth === scrollWidth
- Shows the label as the tooltip title when scrollWidth > offsetWidth
- Re-evaluates on subsequent ResizeObserver fires (truncated then
  fits again)

ResizeObserver is mocked to capture callbacks so the tests can
trigger re-measurement deterministically; .MuiChip-label
dimensions are overridden via Object.defineProperty so the
overflow check returns a known result in jsdom.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@NoopDog NoopDog merged commit d473ab6 into main Jun 5, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FilterTag overflow detection reads ref during render

3 participants