mirror of
https://github.com/flutter/flutter
synced 2024-09-13 05:11:45 +00:00
[a11y] Add isEnabled semantics flag to text field (#143334)
Add a semantics flag to text field to fix https://github.com/flutter/flutter/issues/143337 (in IOS the disabled text field is not read `dimmed`) internal: b/322345393
This commit is contained in:
parent
5025681129
commit
14bce28f3c
|
@ -1574,6 +1574,7 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
|
|||
animation: controller, // changes the _currentLength
|
||||
builder: (BuildContext context, Widget? child) {
|
||||
return Semantics(
|
||||
enabled: _isEnabled,
|
||||
maxValueLength: semanticsMaxValueLength,
|
||||
currentValueLength: _currentLength,
|
||||
onTap: widget.readOnly ? null : () {
|
||||
|
|
|
@ -529,8 +529,11 @@ void main() {
|
|||
children: <TestSemantics>[
|
||||
TestSemantics(
|
||||
id: 4,
|
||||
flags: <SemanticsFlag>[SemanticsFlag.isTextField,
|
||||
SemanticsFlag.hasEnabledState, SemanticsFlag.isEnabled,],
|
||||
flags: <SemanticsFlag>[
|
||||
SemanticsFlag.isTextField,
|
||||
SemanticsFlag.hasEnabledState,
|
||||
SemanticsFlag.isEnabled,
|
||||
],
|
||||
actions: <SemanticsAction>[SemanticsAction.tap,
|
||||
SemanticsAction.didGainAccessibilityFocus,],
|
||||
textDirection: TextDirection.ltr,
|
||||
|
|
|
@ -279,6 +279,8 @@ void main() {
|
|||
expect(tester.getSemantics(find.byType(EditableText)), matchesSemantics(
|
||||
label: 'Enter Date',
|
||||
isTextField: true,
|
||||
hasEnabledState: true,
|
||||
isEnabled: true,
|
||||
isFocused: true,
|
||||
value: '01/15/2016',
|
||||
hasTapAction: true,
|
||||
|
|
|
@ -670,6 +670,8 @@ void main() {
|
|||
id: 9,
|
||||
flags: <SemanticsFlag>[
|
||||
SemanticsFlag.isTextField,
|
||||
SemanticsFlag.hasEnabledState,
|
||||
SemanticsFlag.isEnabled,
|
||||
SemanticsFlag.isFocused,
|
||||
SemanticsFlag.isHeader,
|
||||
if (debugDefaultTargetPlatformOverride != TargetPlatform.iOS &&
|
||||
|
@ -818,6 +820,8 @@ void main() {
|
|||
id: 11,
|
||||
flags: <SemanticsFlag>[
|
||||
SemanticsFlag.isTextField,
|
||||
SemanticsFlag.hasEnabledState,
|
||||
SemanticsFlag.isEnabled,
|
||||
SemanticsFlag.isFocused,
|
||||
SemanticsFlag.isHeader,
|
||||
if (debugDefaultTargetPlatformOverride != TargetPlatform.iOS &&
|
||||
|
|
|
@ -746,7 +746,7 @@ void main() {
|
|||
children: <TestSemantics>[
|
||||
TestSemantics(
|
||||
id: 4,
|
||||
flags: <SemanticsFlag>[SemanticsFlag.isTextField],
|
||||
flags: <SemanticsFlag>[SemanticsFlag.isTextField, SemanticsFlag.hasEnabledState, SemanticsFlag.isEnabled],
|
||||
actions: <SemanticsAction>[
|
||||
SemanticsAction.tap,
|
||||
SemanticsAction.didGainAccessibilityFocus,
|
||||
|
@ -1856,7 +1856,12 @@ void main() {
|
|||
children: <TestSemantics>[
|
||||
TestSemantics(
|
||||
id: 1,
|
||||
flags: <SemanticsFlag>[SemanticsFlag.isTextField, SemanticsFlag.isFocused],
|
||||
flags: <SemanticsFlag>[
|
||||
SemanticsFlag.isTextField,
|
||||
SemanticsFlag.hasEnabledState,
|
||||
SemanticsFlag.isEnabled,
|
||||
SemanticsFlag.isFocused,
|
||||
],
|
||||
actions: <SemanticsAction>[
|
||||
SemanticsAction.tap,
|
||||
SemanticsAction.moveCursorBackwardByCharacter,
|
||||
|
@ -5189,6 +5194,8 @@ void main() {
|
|||
],
|
||||
flags: <SemanticsFlag>[
|
||||
SemanticsFlag.isTextField,
|
||||
SemanticsFlag.hasEnabledState,
|
||||
SemanticsFlag.isEnabled,
|
||||
],
|
||||
),
|
||||
TestSemantics.rootChild(
|
||||
|
@ -6530,7 +6537,7 @@ void main() {
|
|||
),
|
||||
);
|
||||
|
||||
expect(semantics, includesNodeWith(flags: <SemanticsFlag>[SemanticsFlag.isTextField]));
|
||||
expect(semantics, includesNodeWith(flags: <SemanticsFlag>[SemanticsFlag.isTextField, SemanticsFlag.hasEnabledState, SemanticsFlag.isEnabled]));
|
||||
|
||||
semantics.dispose();
|
||||
});
|
||||
|
@ -6944,7 +6951,7 @@ void main() {
|
|||
);
|
||||
|
||||
expect(semantics, includesNodeWith(
|
||||
flags: <SemanticsFlag>[SemanticsFlag.isTextField],
|
||||
flags: <SemanticsFlag>[SemanticsFlag.isTextField, SemanticsFlag.hasEnabledState, SemanticsFlag.isEnabled],
|
||||
maxValueLength: 10,
|
||||
currentValueLength: 0,
|
||||
));
|
||||
|
@ -6959,7 +6966,12 @@ void main() {
|
|||
await tester.pump();
|
||||
|
||||
expect(semantics, includesNodeWith(
|
||||
flags: <SemanticsFlag>[SemanticsFlag.isTextField, SemanticsFlag.isFocused],
|
||||
flags: <SemanticsFlag>[
|
||||
SemanticsFlag.isTextField,
|
||||
SemanticsFlag.hasEnabledState,
|
||||
SemanticsFlag.isEnabled,
|
||||
SemanticsFlag.isFocused,
|
||||
],
|
||||
maxValueLength: 10,
|
||||
currentValueLength: 3,
|
||||
));
|
||||
|
@ -6985,7 +6997,12 @@ void main() {
|
|||
|
||||
expect(
|
||||
semantics,
|
||||
includesNodeWith(flags: <SemanticsFlag>[SemanticsFlag.isTextField, SemanticsFlag.isReadOnly]),
|
||||
includesNodeWith(flags: <SemanticsFlag>[
|
||||
SemanticsFlag.isTextField,
|
||||
SemanticsFlag.hasEnabledState,
|
||||
SemanticsFlag.isEnabled,
|
||||
SemanticsFlag.isReadOnly,
|
||||
]),
|
||||
);
|
||||
|
||||
semantics.dispose();
|
||||
|
@ -8050,6 +8067,8 @@ void main() {
|
|||
],
|
||||
flags: <SemanticsFlag>[
|
||||
SemanticsFlag.isTextField,
|
||||
SemanticsFlag.hasEnabledState,
|
||||
SemanticsFlag.isEnabled,
|
||||
],
|
||||
),
|
||||
],
|
||||
|
@ -8069,6 +8088,8 @@ void main() {
|
|||
],
|
||||
flags: <SemanticsFlag>[
|
||||
SemanticsFlag.isTextField,
|
||||
SemanticsFlag.hasEnabledState,
|
||||
SemanticsFlag.isEnabled,
|
||||
],
|
||||
),
|
||||
],
|
||||
|
@ -8094,6 +8115,8 @@ void main() {
|
|||
],
|
||||
flags: <SemanticsFlag>[
|
||||
SemanticsFlag.isTextField,
|
||||
SemanticsFlag.hasEnabledState,
|
||||
SemanticsFlag.isEnabled,
|
||||
SemanticsFlag.isFocused,
|
||||
],
|
||||
),
|
||||
|
@ -8122,6 +8145,8 @@ void main() {
|
|||
],
|
||||
flags: <SemanticsFlag>[
|
||||
SemanticsFlag.isTextField,
|
||||
SemanticsFlag.hasEnabledState,
|
||||
SemanticsFlag.isEnabled,
|
||||
SemanticsFlag.isFocused,
|
||||
],
|
||||
),
|
||||
|
@ -8149,6 +8174,8 @@ void main() {
|
|||
],
|
||||
flags: <SemanticsFlag>[
|
||||
SemanticsFlag.isTextField,
|
||||
SemanticsFlag.hasEnabledState,
|
||||
SemanticsFlag.isEnabled,
|
||||
SemanticsFlag.isFocused,
|
||||
],
|
||||
),
|
||||
|
@ -8174,6 +8201,8 @@ void main() {
|
|||
textDirection: TextDirection.ltr,
|
||||
flags: <SemanticsFlag>[
|
||||
SemanticsFlag.isTextField,
|
||||
SemanticsFlag.hasEnabledState,
|
||||
SemanticsFlag.isEnabled,
|
||||
],
|
||||
value: 'Hello',
|
||||
)
|
||||
|
@ -8189,6 +8218,8 @@ void main() {
|
|||
textDirection: TextDirection.ltr,
|
||||
flags: <SemanticsFlag>[
|
||||
SemanticsFlag.isTextField,
|
||||
SemanticsFlag.hasEnabledState,
|
||||
SemanticsFlag.isEnabled,
|
||||
SemanticsFlag.isObscured,
|
||||
],
|
||||
)
|
||||
|
@ -8204,6 +8235,8 @@ void main() {
|
|||
textDirection: TextDirection.ltr,
|
||||
flags: <SemanticsFlag>[
|
||||
SemanticsFlag.isTextField,
|
||||
SemanticsFlag.hasEnabledState,
|
||||
SemanticsFlag.isEnabled,
|
||||
],
|
||||
value: 'Hello',
|
||||
)
|
||||
|
@ -8246,6 +8279,8 @@ void main() {
|
|||
],
|
||||
flags: <SemanticsFlag>[
|
||||
SemanticsFlag.isTextField,
|
||||
SemanticsFlag.hasEnabledState,
|
||||
SemanticsFlag.isEnabled,
|
||||
SemanticsFlag.isFocused,
|
||||
],
|
||||
),
|
||||
|
@ -8281,6 +8316,8 @@ void main() {
|
|||
],
|
||||
flags: <SemanticsFlag>[
|
||||
SemanticsFlag.isTextField,
|
||||
SemanticsFlag.hasEnabledState,
|
||||
SemanticsFlag.isEnabled,
|
||||
],
|
||||
),
|
||||
],
|
||||
|
@ -8307,6 +8344,8 @@ void main() {
|
|||
],
|
||||
flags: <SemanticsFlag>[
|
||||
SemanticsFlag.isTextField,
|
||||
SemanticsFlag.hasEnabledState,
|
||||
SemanticsFlag.isEnabled,
|
||||
SemanticsFlag.isFocused,
|
||||
],
|
||||
),
|
||||
|
@ -8337,6 +8376,8 @@ void main() {
|
|||
],
|
||||
flags: <SemanticsFlag>[
|
||||
SemanticsFlag.isTextField,
|
||||
SemanticsFlag.hasEnabledState,
|
||||
SemanticsFlag.isEnabled,
|
||||
SemanticsFlag.isFocused,
|
||||
],
|
||||
),
|
||||
|
@ -8386,6 +8427,8 @@ void main() {
|
|||
],
|
||||
flags: <SemanticsFlag>[
|
||||
SemanticsFlag.isTextField,
|
||||
SemanticsFlag.hasEnabledState,
|
||||
SemanticsFlag.isEnabled,
|
||||
SemanticsFlag.isFocused,
|
||||
],
|
||||
),
|
||||
|
@ -8434,6 +8477,8 @@ void main() {
|
|||
],
|
||||
flags: <SemanticsFlag>[
|
||||
SemanticsFlag.isTextField,
|
||||
SemanticsFlag.hasEnabledState,
|
||||
SemanticsFlag.isEnabled,
|
||||
SemanticsFlag.isFocused,
|
||||
],
|
||||
),
|
||||
|
@ -8470,7 +8515,7 @@ void main() {
|
|||
children: <TestSemantics>[
|
||||
TestSemantics(
|
||||
id: inputFieldId,
|
||||
flags: <SemanticsFlag>[SemanticsFlag.isTextField],
|
||||
flags: <SemanticsFlag>[SemanticsFlag.isTextField, SemanticsFlag.hasEnabledState, SemanticsFlag.isEnabled],
|
||||
actions: <SemanticsAction>[SemanticsAction.tap],
|
||||
value: textInTextField,
|
||||
textDirection: TextDirection.ltr,
|
||||
|
@ -8490,6 +8535,8 @@ void main() {
|
|||
id: inputFieldId,
|
||||
flags: <SemanticsFlag>[
|
||||
SemanticsFlag.isTextField,
|
||||
SemanticsFlag.hasEnabledState,
|
||||
SemanticsFlag.isEnabled,
|
||||
SemanticsFlag.isFocused,
|
||||
],
|
||||
actions: <SemanticsAction>[
|
||||
|
@ -8543,7 +8590,7 @@ void main() {
|
|||
children: <TestSemantics>[
|
||||
TestSemantics(
|
||||
id: inputFieldId,
|
||||
flags: <SemanticsFlag>[SemanticsFlag.isTextField],
|
||||
flags: <SemanticsFlag>[SemanticsFlag.isTextField, SemanticsFlag.hasEnabledState, SemanticsFlag.isEnabled],
|
||||
actions: <SemanticsAction>[SemanticsAction.tap],
|
||||
value: textInTextField,
|
||||
textDirection: TextDirection.ltr,
|
||||
|
@ -8563,6 +8610,8 @@ void main() {
|
|||
id: inputFieldId,
|
||||
flags: <SemanticsFlag>[
|
||||
SemanticsFlag.isTextField,
|
||||
SemanticsFlag.hasEnabledState,
|
||||
SemanticsFlag.isEnabled,
|
||||
SemanticsFlag.isFocused,
|
||||
],
|
||||
actions: <SemanticsAction>[
|
||||
|
@ -8743,6 +8792,8 @@ void main() {
|
|||
],
|
||||
flags: <SemanticsFlag>[
|
||||
SemanticsFlag.isTextField,
|
||||
SemanticsFlag.hasEnabledState,
|
||||
SemanticsFlag.isEnabled,
|
||||
],
|
||||
children: <TestSemantics>[
|
||||
TestSemantics(
|
||||
|
@ -8778,6 +8829,8 @@ void main() {
|
|||
],
|
||||
flags: <SemanticsFlag>[
|
||||
SemanticsFlag.isTextField,
|
||||
SemanticsFlag.hasEnabledState,
|
||||
SemanticsFlag.isEnabled,
|
||||
SemanticsFlag.isFocused,
|
||||
],
|
||||
children: <TestSemantics>[
|
||||
|
@ -8835,6 +8888,8 @@ void main() {
|
|||
],
|
||||
flags: <SemanticsFlag>[
|
||||
SemanticsFlag.isTextField,
|
||||
SemanticsFlag.hasEnabledState,
|
||||
SemanticsFlag.isEnabled,
|
||||
],
|
||||
children: <TestSemantics>[
|
||||
TestSemantics(
|
||||
|
@ -8882,6 +8937,8 @@ void main() {
|
|||
],
|
||||
flags: <SemanticsFlag>[
|
||||
SemanticsFlag.isTextField,
|
||||
SemanticsFlag.hasEnabledState,
|
||||
SemanticsFlag.isEnabled,
|
||||
],
|
||||
children: <TestSemantics>[
|
||||
TestSemantics(
|
||||
|
|
|
@ -1343,7 +1343,12 @@ void main() {
|
|||
label: 'Hour',
|
||||
value: '07',
|
||||
actions: <SemanticsAction>[SemanticsAction.tap],
|
||||
flags: <SemanticsFlag>[SemanticsFlag.isTextField, SemanticsFlag.isMultiline],
|
||||
flags: <SemanticsFlag>[
|
||||
SemanticsFlag.isTextField,
|
||||
SemanticsFlag.hasEnabledState,
|
||||
SemanticsFlag.isEnabled,
|
||||
SemanticsFlag.isMultiline,
|
||||
],
|
||||
),
|
||||
);
|
||||
expect(
|
||||
|
@ -1352,7 +1357,12 @@ void main() {
|
|||
label: 'Minute',
|
||||
value: '00',
|
||||
actions: <SemanticsAction>[SemanticsAction.tap],
|
||||
flags: <SemanticsFlag>[SemanticsFlag.isTextField, SemanticsFlag.isMultiline],
|
||||
flags: <SemanticsFlag>[
|
||||
SemanticsFlag.isTextField,
|
||||
SemanticsFlag.hasEnabledState,
|
||||
SemanticsFlag.isEnabled,
|
||||
SemanticsFlag.isMultiline,
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
|
|
|
@ -883,6 +883,7 @@ void main() {
|
|||
group('simulatedTraversal', () {
|
||||
final List<Matcher> fullTraversalMatchers = <Matcher>[
|
||||
containsSemantics(isHeader: true, label: 'Semantics Test'),
|
||||
containsSemantics(label: 'Text Field'),
|
||||
containsSemantics(isTextField: true),
|
||||
containsSemantics(label: 'Off Switch'),
|
||||
containsSemantics(hasToggledState: true),
|
||||
|
@ -913,7 +914,7 @@ void main() {
|
|||
await tester.pumpWidget(const MaterialApp(home: _SemanticsTestWidget()));
|
||||
|
||||
// We're expecting the traversal to start where the slider is.
|
||||
final List<Matcher> expectedMatchers = <Matcher>[...fullTraversalMatchers]..removeRange(0, 8);
|
||||
final List<Matcher> expectedMatchers = <Matcher>[...fullTraversalMatchers]..removeRange(0, 9);
|
||||
|
||||
expect(
|
||||
tester.semantics.simulatedAccessibilityTraversal(start: find.byType(Slider)),
|
||||
|
@ -935,7 +936,7 @@ void main() {
|
|||
await tester.pumpWidget(const MaterialApp(home: _SemanticsTestWidget()));
|
||||
|
||||
// We're expecting the traversal to end where the slider is, inclusive.
|
||||
final Iterable<Matcher> expectedMatchers = <Matcher>[...fullTraversalMatchers].getRange(0, 9);
|
||||
final Iterable<Matcher> expectedMatchers = <Matcher>[...fullTraversalMatchers].getRange(0, 10);
|
||||
|
||||
expect(
|
||||
tester.semantics.simulatedAccessibilityTraversal(end: find.byType(Slider)),
|
||||
|
@ -957,7 +958,7 @@ void main() {
|
|||
await tester.pumpWidget(const MaterialApp(home: _SemanticsTestWidget()));
|
||||
|
||||
// We're expecting the traversal to start at the text field and end at the slider.
|
||||
final Iterable<Matcher> expectedMatchers = <Matcher>[...fullTraversalMatchers].getRange(1, 9);
|
||||
final Iterable<Matcher> expectedMatchers = <Matcher>[...fullTraversalMatchers].getRange(1, 10);
|
||||
|
||||
expect(
|
||||
tester.semantics.simulatedAccessibilityTraversal(
|
||||
|
@ -1661,7 +1662,7 @@ class _SemanticsTestWidget extends StatelessWidget {
|
|||
child: Column(
|
||||
children: <Widget>[
|
||||
const _SemanticsTestCard(
|
||||
label: 'TextField',
|
||||
label: 'Text Field',
|
||||
widget: TextField(),
|
||||
),
|
||||
_SemanticsTestCard(
|
||||
|
|
Loading…
Reference in a new issue