Skip to content

Commit a9fecf2

Browse files
authored
Add breaking change "Material Chip button semantics" (#4312)
1 parent 7a1807f commit a9fecf2

File tree

2 files changed

+158
-0
lines changed

2 files changed

+158
-0
lines changed

src/docs/release/breaking-changes/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ release, and listed in alphabetical order:
4343
* [The RenderEditable needs to be laid out before hit testing][]
4444
* [The Route Transition record and Transition delegate updates][]
4545
* [TestWidgetsFlutterBinding.clock][]
46+
* [Material Chip button semantics][]
4647

4748
[Actions API revision]: /docs/release/breaking-changes/actions-api-revision
4849
[Adding 'linux' and 'windows' to TargetPlatform enum]: /docs/release/breaking-changes/target-platform-linux-windows
@@ -72,3 +73,4 @@ release, and listed in alphabetical order:
7273
[The Route and Navigator refactoring]: /docs/release/breaking-changes/route-navigator-refactoring
7374
[The Route Transition record and Transition delegate updates]: /docs/release/breaking-changes/route-transition-record-and-transition-delegate
7475
[ThemeData's accent properties]: /docs/release/breaking-changes/theme-data-accent-properties
76+
[Material Chip button semantics]: /docs/release/breaking-changes/material-chip-button-semantics
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
---
2+
title: Material Chip button semantics
3+
description: Interactive Material Chips are now semantically marked as buttons.
4+
---
5+
6+
## Summary
7+
8+
Flutter now applies the semantic label of `button` to all interactive [Material
9+
Chips][] for accessibility purposes.
10+
11+
## Context
12+
13+
Interactive Material Chips (namely [`ActionChip`][], [`ChoiceChip`][],
14+
[`FilterChip`][], and [`InputChip`][]) are now semantically marked as being
15+
buttons. However, the non-interactive information [`Chip`][] is not.
16+
17+
Marking Chips as buttons helps accessibility tools, search engines, and other
18+
semantic analysis software understand the meaning of an app. For example, it
19+
allows screen readers (such as TalkBack on Android and VoiceOver on iOS) to
20+
announce a tappable Chip as a "button", which can assist users in navigating
21+
your app. Prior to this change, users of accessibility tools may have had a
22+
subpar experience, unless you implemented a workaround by manually adding the
23+
missing semantics to the Chip widgets in your app.
24+
25+
## Description of change
26+
27+
The outermost [`Semantics`][] widget that wraps all Chip classes to describe
28+
their semantic properties has been modified.
29+
30+
For [`ActionChip`][], [`ChoiceChip`][], [`FilterChip`][], and [`InputChip`][]:
31+
32+
- The [`button`][`SemanticsProperties.button`] property is set to `true`.
33+
- The [`enabled`][`SemanticsProperties.enabled`] property reflects whether the
34+
Chip is _currently_ tappable (by having a callback set).
35+
36+
These property changes bring interactive Chips' semantic behavior in-line with
37+
that of other [Material Buttons][].
38+
39+
For the non-interactive information [`Chip`][]:
40+
41+
- The [`button`][`SemanticsProperties.button`] property is set to `false`.
42+
- The [`enabled`][`SemanticsProperties.enabled`] property is set to `null`.
43+
44+
## Migration guide
45+
46+
**You might not need to perform any migration.** This change only affects you if
47+
you worked around the issue of Material Chips missing `button` semantics by
48+
wrapping the widget given to the `label` field of a `Chip` with a `Semantics`
49+
widget marked as `button: true`. **In this case, the inner and outer `button`
50+
semantics conflict, resulting in the tappable area of the button shrinking
51+
down to the size of the label after this change is introduced.** Fix this issue
52+
either by deleting that `Semantics` widget and replacing it with its child,
53+
or by removing the `button: true` property if other semantic properties still
54+
need to be applied to the `label` widget of the Chip.
55+
56+
The following snippets use [`InputChip`][] as an example, but the same process
57+
applies to [`ActionChip`][], [`ChoiceChip`][], and [`FilterChip`][] as well.
58+
59+
**Case 1: remove the `Semantics` widget.**
60+
61+
Code before migration:
62+
63+
<!-- skip -->
64+
```dart
65+
Widget myInputChip = InputChip(
66+
onPressed: () {},
67+
label: Semantics(
68+
button: true,
69+
child: Text('My Input Chip'),
70+
),
71+
);
72+
```
73+
74+
Code after migration:
75+
76+
<!-- skip -->
77+
```dart
78+
Widget myInputChip = InputChip(
79+
onPressed: () {},
80+
label: Text('My Input Chip'),
81+
);
82+
```
83+
84+
**Case 2: remove `button:true` from the `Semantics` widget.**
85+
86+
Code before migration:
87+
88+
<!-- skip -->
89+
```dart
90+
Widget myInputChip = InputChip(
91+
onPressed: () {},
92+
label: Semantics(
93+
button: true,
94+
hint: 'Example Hint',
95+
child: Text('My Input Chip'),
96+
),
97+
);
98+
```
99+
100+
Code after migration:
101+
102+
<!-- skip -->
103+
```dart
104+
Widget myInputChip = InputChip(
105+
onPressed: () {},
106+
label: Semantics(
107+
hint: 'Example Hint',
108+
child: Text('My Input Chip'),
109+
),
110+
);
111+
```
112+
113+
## Timeline
114+
115+
Landed in version: TBD<br> In stable release: not yet
116+
117+
## References
118+
119+
{% include master-api.md %}
120+
121+
API documentation:
122+
* [`ActionChip`][]
123+
* [`Chip`][]
124+
* [`ChoiceChip`][]
125+
* [`FilterChip`][]
126+
* [`InputChip`][]
127+
* [Material Buttons][]
128+
* [Material Chips][]
129+
* [`Semantics`][]
130+
* [`SemanticsProperties.button`][]
131+
* [`SemanticsProperties.enabled`][]
132+
133+
Relevant issues:
134+
* [flutter/flutter#58010][]
135+
136+
Relevant PRs:
137+
* [Tweaking Material Chip a11y semantics to match buttons][]
138+
* [Revert "Tweaking Material Chip a11y semantics to match buttons (#60141)"][]
139+
* [Re-land "Tweaking Material Chip a11y semantics to match buttons (#60141)"][]
140+
141+
[`ActionChip`]: {{site.api}}/flutter/material/ActionChip-class.html
142+
[`Chip`]: {{site.api}}/flutter/material/Chip-class.html
143+
[`ChoiceChip`]: {{site.api}}/flutter/material/ChoiceChip-class.html
144+
[`FilterChip`]: {{site.api}}/flutter/material/FilterChip-class.html
145+
[`InputChip`]: {{site.api}}/flutter/material/InputChip-class.html
146+
[Material Buttons]: {{site.material}}/components/buttons
147+
[Material Chips]: {{site.material}}/components/chips
148+
[`Semantics`]: {{site.api}}/flutter/widgets/Semantics-class.html
149+
[`SemanticsProperties.button`]: {{site.api}}/flutter/semantics/SemanticsProperties/button.html
150+
[`SemanticsProperties.enabled`]: {{site.api}}/flutter/semantics/SemanticsProperties/enabled.html
151+
152+
[flutter/flutter#58010]: {{site.github}}/flutter/flutter/issues/58010
153+
154+
[Tweaking Material Chip a11y semantics to match buttons]: {{site.github}}/flutter/flutter/pull/60141
155+
[Revert "Tweaking Material Chip a11y semantics to match buttons (#60141)"]: {{site.github}}/flutter/flutter/pull/60645
156+
[Re-land "Tweaking Material Chip a11y semantics to match buttons (#60141)"]: {{site.github}}/flutter/flutter/pull/61048

0 commit comments

Comments
 (0)