Skip to content

[material_ui] Preserve Tooltip semantics when disabled by TooltipVisibility#12153

Closed
devzahirul wants to merge 1 commit into
flutter:mainfrom
devzahirul:fix-material-ui-tooltip-visibility-semantics
Closed

[material_ui] Preserve Tooltip semantics when disabled by TooltipVisibility#12153
devzahirul wants to merge 1 commit into
flutter:mainfrom
devzahirul:fix-material-ui-tooltip-visibility-semantics

Conversation

@devzahirul

Copy link
Copy Markdown

TooltipVisibility(visible: false) is documented to "only visually" disable tooltips while it "continues to provide any semantic information that is provided". Since the RawTooltip refactor (flutter/flutter#177678), TooltipState.build skips the RawTooltip wrapper entirely when the tooltip is disabled. Because the Semantics(tooltip:) annotation now lives inside RawTooltip, it is dropped along with it, so assistive technologies stop announcing the tooltip message — for example, an IconButton with tooltip: 'Add' under TooltipVisibility(visible: false) is announced as just "button". Before that refactor, the Semantics wrapper was applied unconditionally and only gesture handling was gated on visibility.

This change restores the documented behavior: when a TooltipVisibility ancestor disables the tooltip, the child is still wrapped in the same Semantics(tooltip:) annotation that RawTooltip applies when the tooltip is enabled, honoring excludeFromSemantics. It adds a regression test that fails without the fix, plus a test verifying that excludeFromSemantics: true still suppresses the semantics when the tooltip is disabled.

This supersedes flutter/flutter#189171, which targeted the frozen Material library in flutter/flutter and is being ported here per the porting instructions in flutter/flutter#188444 and the code freeze policy in flutter/flutter#184093.

material_ui is not yet published (publish_to: none), so no version/CHANGELOG update is included, matching other [material_ui] PRs.

Fixes flutter/flutter#189062

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. 2

@google-cla

google-cla Bot commented Jul 9, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request ensures that a Tooltip still contributes semantics to assistive technology when its visibility is disabled by a TooltipVisibility ancestor, and adds corresponding tests. The reviewer suggests optimizing the implementation by using else if (!excludeFromSemantics) to avoid building an unnecessary Semantics widget when semantics are excluded.

Comment on lines +569 to 577
} else {
// A TooltipVisibility ancestor has disabled the tooltip overlay and its
// triggers, but the message should still be reported to assistive
// technology, matching what RawTooltip does when the tooltip is enabled.
effectiveChild = Semantics(
tooltip: excludeFromSemantics ? null : _tooltipMessage,
child: effectiveChild,
);
}

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.

medium

When excludeFromSemantics is true, wrapping the child in a Semantics widget with a null tooltip is redundant and adds unnecessary overhead to the widget tree. We can avoid building the Semantics widget entirely in this case by changing the else block to an else if (!excludeFromSemantics) block.

    } else if (!excludeFromSemantics) {
      // A TooltipVisibility ancestor has disabled the tooltip overlay and its
      // triggers, but the message should still be reported to assistive
      // technology, matching what RawTooltip does when the tooltip is enabled.
      effectiveChild = Semantics(
        tooltip: _tooltipMessage,
        child: effectiveChild,
      );
    }

@Piinks

Piinks commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

This package is not accepting contributions yet. We will announce when it is. Thank you, closing for now to keep the queue clear for PRs essential to pre-release.

@Piinks Piinks closed this Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p: material_ui triage-framework Should be looked at in framework triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Setting TooltipVisibility(visible: false) prevents tooltips contributing semantics

2 participants