[go: nahoru, domu]

Skip to content

Commit

Permalink
Add Selected semantics to IconButton (#128547)
Browse files Browse the repository at this point in the history
fixes: #127145

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] All existing and new tests are passing.

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

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[test-exempt]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
[Discord]: https://github.com/flutter/flutter/wiki/Chat

---------

Co-authored-by: Qun Cheng <36861262+QuncCccccc@users.noreply.github.com>
  • Loading branch information
hangyujin and QuncCccccc committed Jun 9, 2023
1 parent 9c0c611 commit af7a8f6
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/flutter/lib/src/material/icon_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,10 @@ class _SelectableIconButtonState extends State<_SelectableIconButton> {
onPressed: widget.onPressed,
variant: widget.variant,
toggleable: toggleable,
child: widget.child,
child: Semantics(
selected: widget.isSelected,
child: widget.child,
),
);
}
}
Expand Down
56 changes: 56 additions & 0 deletions packages/flutter/test/material/icon_button_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,62 @@ void main() {
semantics.dispose();
});

testWidgets('IconButton Semantics (selected) - M3', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester);

await tester.pumpWidget(
wrap(
useMaterial3: true,
child: IconButton(
onPressed: mockOnPressedFunction.handler,
isSelected: true,
icon: const Icon(Icons.link, semanticLabel: 'link'),
),
),
);

expect(
semantics,
hasSemantics(
TestSemantics.root(
children: <TestSemantics>[
TestSemantics(
textDirection: TextDirection.ltr,
children: <TestSemantics>[
TestSemantics(
children: <TestSemantics>[
TestSemantics(
flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
children: <TestSemantics>[
TestSemantics(
actions: <SemanticsAction>[
SemanticsAction.tap,
],
flags: <SemanticsFlag>[
SemanticsFlag.hasEnabledState,
SemanticsFlag.isButton,
SemanticsFlag.isEnabled,
SemanticsFlag.isFocusable,
SemanticsFlag.isSelected,
],
label: 'link',
),
],
),
],
),
],
),
],
),
ignoreId: true,
ignoreRect: true,
ignoreTransform: true,
),
);
semantics.dispose();
});

testWidgets('IconButton loses focus when disabled.', (WidgetTester tester) async {
final FocusNode focusNode = FocusNode(debugLabel: 'IconButton');
await tester.pumpWidget(
Expand Down

0 comments on commit af7a8f6

Please sign in to comment.