[material_ui] Preserve Tooltip semantics when disabled by TooltipVisibility#12153
[material_ui] Preserve Tooltip semantics when disabled by TooltipVisibility#12153devzahirul wants to merge 1 commit into
Conversation
|
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. |
There was a problem hiding this comment.
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.
| } 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, | ||
| ); | ||
| } |
There was a problem hiding this comment.
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,
);
}|
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. |
TooltipVisibility(visible: false)is documented to "only visually" disable tooltips while it "continues to provide any semantic information that is provided". Since theRawTooltiprefactor (flutter/flutter#177678),TooltipState.buildskips theRawTooltipwrapper entirely when the tooltip is disabled. Because theSemantics(tooltip:)annotation now lives insideRawTooltip, it is dropped along with it, so assistive technologies stop announcing the tooltip message — for example, anIconButtonwithtooltip: 'Add'underTooltipVisibility(visible: false)is announced as just "button". Before that refactor, theSemanticswrapper was applied unconditionally and only gesture handling was gated on visibility.This change restores the documented behavior: when a
TooltipVisibilityancestor disables the tooltip, the child is still wrapped in the sameSemantics(tooltip:)annotation thatRawTooltipapplies when the tooltip is enabled, honoringexcludeFromSemantics. It adds a regression test that fails without the fix, plus a test verifying thatexcludeFromSemantics: truestill 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_uiis 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
[shared_preferences]///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Footnotes
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