Unverified Commit fdb17ab0 authored by hangyu's avatar hangyu Committed by GitHub

Reland [a11y] Add isEnabled semantics flag to text field (#143601)

Reland #143334
parent 2c2fed1d
...@@ -1574,6 +1574,7 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements ...@@ -1574,6 +1574,7 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
animation: controller, // changes the _currentLength animation: controller, // changes the _currentLength
builder: (BuildContext context, Widget? child) { builder: (BuildContext context, Widget? child) {
return Semantics( return Semantics(
enabled: _isEnabled,
maxValueLength: semanticsMaxValueLength, maxValueLength: semanticsMaxValueLength,
currentValueLength: _currentLength, currentValueLength: _currentLength,
onTap: widget.readOnly ? null : () { onTap: widget.readOnly ? null : () {
......
...@@ -529,8 +529,11 @@ void main() { ...@@ -529,8 +529,11 @@ void main() {
children: <TestSemantics>[ children: <TestSemantics>[
TestSemantics( TestSemantics(
id: 4, id: 4,
flags: <SemanticsFlag>[SemanticsFlag.isTextField, flags: <SemanticsFlag>[
SemanticsFlag.hasEnabledState, SemanticsFlag.isEnabled,], SemanticsFlag.isTextField,
SemanticsFlag.hasEnabledState,
SemanticsFlag.isEnabled,
],
actions: <SemanticsAction>[SemanticsAction.tap, actions: <SemanticsAction>[SemanticsAction.tap,
SemanticsAction.didGainAccessibilityFocus,], SemanticsAction.didGainAccessibilityFocus,],
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
......
...@@ -279,6 +279,8 @@ void main() { ...@@ -279,6 +279,8 @@ void main() {
expect(tester.getSemantics(find.byType(EditableText)), matchesSemantics( expect(tester.getSemantics(find.byType(EditableText)), matchesSemantics(
label: 'Enter Date', label: 'Enter Date',
isTextField: true, isTextField: true,
hasEnabledState: true,
isEnabled: true,
isFocused: true, isFocused: true,
value: '01/15/2016', value: '01/15/2016',
hasTapAction: true, hasTapAction: true,
......
...@@ -670,6 +670,8 @@ void main() { ...@@ -670,6 +670,8 @@ void main() {
id: 9, id: 9,
flags: <SemanticsFlag>[ flags: <SemanticsFlag>[
SemanticsFlag.isTextField, SemanticsFlag.isTextField,
SemanticsFlag.hasEnabledState,
SemanticsFlag.isEnabled,
SemanticsFlag.isFocused, SemanticsFlag.isFocused,
SemanticsFlag.isHeader, SemanticsFlag.isHeader,
if (debugDefaultTargetPlatformOverride != TargetPlatform.iOS && if (debugDefaultTargetPlatformOverride != TargetPlatform.iOS &&
...@@ -818,6 +820,8 @@ void main() { ...@@ -818,6 +820,8 @@ void main() {
id: 11, id: 11,
flags: <SemanticsFlag>[ flags: <SemanticsFlag>[
SemanticsFlag.isTextField, SemanticsFlag.isTextField,
SemanticsFlag.hasEnabledState,
SemanticsFlag.isEnabled,
SemanticsFlag.isFocused, SemanticsFlag.isFocused,
SemanticsFlag.isHeader, SemanticsFlag.isHeader,
if (debugDefaultTargetPlatformOverride != TargetPlatform.iOS && if (debugDefaultTargetPlatformOverride != TargetPlatform.iOS &&
......
...@@ -746,7 +746,7 @@ void main() { ...@@ -746,7 +746,7 @@ void main() {
children: <TestSemantics>[ children: <TestSemantics>[
TestSemantics( TestSemantics(
id: 4, id: 4,
flags: <SemanticsFlag>[SemanticsFlag.isTextField], flags: <SemanticsFlag>[SemanticsFlag.isTextField, SemanticsFlag.hasEnabledState, SemanticsFlag.isEnabled],
actions: <SemanticsAction>[ actions: <SemanticsAction>[
SemanticsAction.tap, SemanticsAction.tap,
SemanticsAction.didGainAccessibilityFocus, SemanticsAction.didGainAccessibilityFocus,
...@@ -1856,7 +1856,12 @@ void main() { ...@@ -1856,7 +1856,12 @@ void main() {
children: <TestSemantics>[ children: <TestSemantics>[
TestSemantics( TestSemantics(
id: 1, id: 1,
flags: <SemanticsFlag>[SemanticsFlag.isTextField, SemanticsFlag.isFocused], flags: <SemanticsFlag>[
SemanticsFlag.isTextField,
SemanticsFlag.hasEnabledState,
SemanticsFlag.isEnabled,
SemanticsFlag.isFocused,
],
actions: <SemanticsAction>[ actions: <SemanticsAction>[
SemanticsAction.tap, SemanticsAction.tap,
SemanticsAction.moveCursorBackwardByCharacter, SemanticsAction.moveCursorBackwardByCharacter,
...@@ -5189,6 +5194,8 @@ void main() { ...@@ -5189,6 +5194,8 @@ void main() {
], ],
flags: <SemanticsFlag>[ flags: <SemanticsFlag>[
SemanticsFlag.isTextField, SemanticsFlag.isTextField,
SemanticsFlag.hasEnabledState,
SemanticsFlag.isEnabled,
], ],
), ),
TestSemantics.rootChild( TestSemantics.rootChild(
...@@ -6530,7 +6537,7 @@ void main() { ...@@ -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(); semantics.dispose();
}); });
...@@ -6944,7 +6951,7 @@ void main() { ...@@ -6944,7 +6951,7 @@ void main() {
); );
expect(semantics, includesNodeWith( expect(semantics, includesNodeWith(
flags: <SemanticsFlag>[SemanticsFlag.isTextField], flags: <SemanticsFlag>[SemanticsFlag.isTextField, SemanticsFlag.hasEnabledState, SemanticsFlag.isEnabled],
maxValueLength: 10, maxValueLength: 10,
currentValueLength: 0, currentValueLength: 0,
)); ));
...@@ -6959,7 +6966,12 @@ void main() { ...@@ -6959,7 +6966,12 @@ void main() {
await tester.pump(); await tester.pump();
expect(semantics, includesNodeWith( expect(semantics, includesNodeWith(
flags: <SemanticsFlag>[SemanticsFlag.isTextField, SemanticsFlag.isFocused], flags: <SemanticsFlag>[
SemanticsFlag.isTextField,
SemanticsFlag.hasEnabledState,
SemanticsFlag.isEnabled,
SemanticsFlag.isFocused,
],
maxValueLength: 10, maxValueLength: 10,
currentValueLength: 3, currentValueLength: 3,
)); ));
...@@ -6985,7 +6997,12 @@ void main() { ...@@ -6985,7 +6997,12 @@ void main() {
expect( expect(
semantics, semantics,
includesNodeWith(flags: <SemanticsFlag>[SemanticsFlag.isTextField, SemanticsFlag.isReadOnly]), includesNodeWith(flags: <SemanticsFlag>[
SemanticsFlag.isTextField,
SemanticsFlag.hasEnabledState,
SemanticsFlag.isEnabled,
SemanticsFlag.isReadOnly,
]),
); );
semantics.dispose(); semantics.dispose();
...@@ -8011,6 +8028,8 @@ void main() { ...@@ -8011,6 +8028,8 @@ void main() {
], ],
flags: <SemanticsFlag>[ flags: <SemanticsFlag>[
SemanticsFlag.isTextField, SemanticsFlag.isTextField,
SemanticsFlag.hasEnabledState,
SemanticsFlag.isEnabled,
], ],
), ),
], ],
...@@ -8030,6 +8049,8 @@ void main() { ...@@ -8030,6 +8049,8 @@ void main() {
], ],
flags: <SemanticsFlag>[ flags: <SemanticsFlag>[
SemanticsFlag.isTextField, SemanticsFlag.isTextField,
SemanticsFlag.hasEnabledState,
SemanticsFlag.isEnabled,
], ],
), ),
], ],
...@@ -8055,6 +8076,8 @@ void main() { ...@@ -8055,6 +8076,8 @@ void main() {
], ],
flags: <SemanticsFlag>[ flags: <SemanticsFlag>[
SemanticsFlag.isTextField, SemanticsFlag.isTextField,
SemanticsFlag.hasEnabledState,
SemanticsFlag.isEnabled,
SemanticsFlag.isFocused, SemanticsFlag.isFocused,
], ],
), ),
...@@ -8083,6 +8106,8 @@ void main() { ...@@ -8083,6 +8106,8 @@ void main() {
], ],
flags: <SemanticsFlag>[ flags: <SemanticsFlag>[
SemanticsFlag.isTextField, SemanticsFlag.isTextField,
SemanticsFlag.hasEnabledState,
SemanticsFlag.isEnabled,
SemanticsFlag.isFocused, SemanticsFlag.isFocused,
], ],
), ),
...@@ -8110,6 +8135,8 @@ void main() { ...@@ -8110,6 +8135,8 @@ void main() {
], ],
flags: <SemanticsFlag>[ flags: <SemanticsFlag>[
SemanticsFlag.isTextField, SemanticsFlag.isTextField,
SemanticsFlag.hasEnabledState,
SemanticsFlag.isEnabled,
SemanticsFlag.isFocused, SemanticsFlag.isFocused,
], ],
), ),
...@@ -8135,6 +8162,8 @@ void main() { ...@@ -8135,6 +8162,8 @@ void main() {
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
flags: <SemanticsFlag>[ flags: <SemanticsFlag>[
SemanticsFlag.isTextField, SemanticsFlag.isTextField,
SemanticsFlag.hasEnabledState,
SemanticsFlag.isEnabled,
], ],
value: 'Hello', value: 'Hello',
) )
...@@ -8150,6 +8179,8 @@ void main() { ...@@ -8150,6 +8179,8 @@ void main() {
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
flags: <SemanticsFlag>[ flags: <SemanticsFlag>[
SemanticsFlag.isTextField, SemanticsFlag.isTextField,
SemanticsFlag.hasEnabledState,
SemanticsFlag.isEnabled,
SemanticsFlag.isObscured, SemanticsFlag.isObscured,
], ],
) )
...@@ -8165,6 +8196,8 @@ void main() { ...@@ -8165,6 +8196,8 @@ void main() {
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
flags: <SemanticsFlag>[ flags: <SemanticsFlag>[
SemanticsFlag.isTextField, SemanticsFlag.isTextField,
SemanticsFlag.hasEnabledState,
SemanticsFlag.isEnabled,
], ],
value: 'Hello', value: 'Hello',
) )
...@@ -8207,6 +8240,8 @@ void main() { ...@@ -8207,6 +8240,8 @@ void main() {
], ],
flags: <SemanticsFlag>[ flags: <SemanticsFlag>[
SemanticsFlag.isTextField, SemanticsFlag.isTextField,
SemanticsFlag.hasEnabledState,
SemanticsFlag.isEnabled,
SemanticsFlag.isFocused, SemanticsFlag.isFocused,
], ],
), ),
...@@ -8242,6 +8277,8 @@ void main() { ...@@ -8242,6 +8277,8 @@ void main() {
], ],
flags: <SemanticsFlag>[ flags: <SemanticsFlag>[
SemanticsFlag.isTextField, SemanticsFlag.isTextField,
SemanticsFlag.hasEnabledState,
SemanticsFlag.isEnabled,
], ],
), ),
], ],
...@@ -8268,6 +8305,8 @@ void main() { ...@@ -8268,6 +8305,8 @@ void main() {
], ],
flags: <SemanticsFlag>[ flags: <SemanticsFlag>[
SemanticsFlag.isTextField, SemanticsFlag.isTextField,
SemanticsFlag.hasEnabledState,
SemanticsFlag.isEnabled,
SemanticsFlag.isFocused, SemanticsFlag.isFocused,
], ],
), ),
...@@ -8298,6 +8337,8 @@ void main() { ...@@ -8298,6 +8337,8 @@ void main() {
], ],
flags: <SemanticsFlag>[ flags: <SemanticsFlag>[
SemanticsFlag.isTextField, SemanticsFlag.isTextField,
SemanticsFlag.hasEnabledState,
SemanticsFlag.isEnabled,
SemanticsFlag.isFocused, SemanticsFlag.isFocused,
], ],
), ),
...@@ -8347,6 +8388,8 @@ void main() { ...@@ -8347,6 +8388,8 @@ void main() {
], ],
flags: <SemanticsFlag>[ flags: <SemanticsFlag>[
SemanticsFlag.isTextField, SemanticsFlag.isTextField,
SemanticsFlag.hasEnabledState,
SemanticsFlag.isEnabled,
SemanticsFlag.isFocused, SemanticsFlag.isFocused,
], ],
), ),
...@@ -8395,6 +8438,8 @@ void main() { ...@@ -8395,6 +8438,8 @@ void main() {
], ],
flags: <SemanticsFlag>[ flags: <SemanticsFlag>[
SemanticsFlag.isTextField, SemanticsFlag.isTextField,
SemanticsFlag.hasEnabledState,
SemanticsFlag.isEnabled,
SemanticsFlag.isFocused, SemanticsFlag.isFocused,
], ],
), ),
...@@ -8431,7 +8476,7 @@ void main() { ...@@ -8431,7 +8476,7 @@ void main() {
children: <TestSemantics>[ children: <TestSemantics>[
TestSemantics( TestSemantics(
id: inputFieldId, id: inputFieldId,
flags: <SemanticsFlag>[SemanticsFlag.isTextField], flags: <SemanticsFlag>[SemanticsFlag.isTextField, SemanticsFlag.hasEnabledState, SemanticsFlag.isEnabled],
actions: <SemanticsAction>[SemanticsAction.tap], actions: <SemanticsAction>[SemanticsAction.tap],
value: textInTextField, value: textInTextField,
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
...@@ -8451,6 +8496,8 @@ void main() { ...@@ -8451,6 +8496,8 @@ void main() {
id: inputFieldId, id: inputFieldId,
flags: <SemanticsFlag>[ flags: <SemanticsFlag>[
SemanticsFlag.isTextField, SemanticsFlag.isTextField,
SemanticsFlag.hasEnabledState,
SemanticsFlag.isEnabled,
SemanticsFlag.isFocused, SemanticsFlag.isFocused,
], ],
actions: <SemanticsAction>[ actions: <SemanticsAction>[
...@@ -8504,7 +8551,7 @@ void main() { ...@@ -8504,7 +8551,7 @@ void main() {
children: <TestSemantics>[ children: <TestSemantics>[
TestSemantics( TestSemantics(
id: inputFieldId, id: inputFieldId,
flags: <SemanticsFlag>[SemanticsFlag.isTextField], flags: <SemanticsFlag>[SemanticsFlag.isTextField, SemanticsFlag.hasEnabledState, SemanticsFlag.isEnabled],
actions: <SemanticsAction>[SemanticsAction.tap], actions: <SemanticsAction>[SemanticsAction.tap],
value: textInTextField, value: textInTextField,
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
...@@ -8524,6 +8571,8 @@ void main() { ...@@ -8524,6 +8571,8 @@ void main() {
id: inputFieldId, id: inputFieldId,
flags: <SemanticsFlag>[ flags: <SemanticsFlag>[
SemanticsFlag.isTextField, SemanticsFlag.isTextField,
SemanticsFlag.hasEnabledState,
SemanticsFlag.isEnabled,
SemanticsFlag.isFocused, SemanticsFlag.isFocused,
], ],
actions: <SemanticsAction>[ actions: <SemanticsAction>[
...@@ -8704,6 +8753,8 @@ void main() { ...@@ -8704,6 +8753,8 @@ void main() {
], ],
flags: <SemanticsFlag>[ flags: <SemanticsFlag>[
SemanticsFlag.isTextField, SemanticsFlag.isTextField,
SemanticsFlag.hasEnabledState,
SemanticsFlag.isEnabled,
], ],
children: <TestSemantics>[ children: <TestSemantics>[
TestSemantics( TestSemantics(
...@@ -8739,6 +8790,8 @@ void main() { ...@@ -8739,6 +8790,8 @@ void main() {
], ],
flags: <SemanticsFlag>[ flags: <SemanticsFlag>[
SemanticsFlag.isTextField, SemanticsFlag.isTextField,
SemanticsFlag.hasEnabledState,
SemanticsFlag.isEnabled,
SemanticsFlag.isFocused, SemanticsFlag.isFocused,
], ],
children: <TestSemantics>[ children: <TestSemantics>[
...@@ -8796,6 +8849,8 @@ void main() { ...@@ -8796,6 +8849,8 @@ void main() {
], ],
flags: <SemanticsFlag>[ flags: <SemanticsFlag>[
SemanticsFlag.isTextField, SemanticsFlag.isTextField,
SemanticsFlag.hasEnabledState,
SemanticsFlag.isEnabled,
], ],
children: <TestSemantics>[ children: <TestSemantics>[
TestSemantics( TestSemantics(
...@@ -8843,6 +8898,8 @@ void main() { ...@@ -8843,6 +8898,8 @@ void main() {
], ],
flags: <SemanticsFlag>[ flags: <SemanticsFlag>[
SemanticsFlag.isTextField, SemanticsFlag.isTextField,
SemanticsFlag.hasEnabledState,
SemanticsFlag.isEnabled,
], ],
children: <TestSemantics>[ children: <TestSemantics>[
TestSemantics( TestSemantics(
......
...@@ -1343,7 +1343,12 @@ void main() { ...@@ -1343,7 +1343,12 @@ void main() {
label: 'Hour', label: 'Hour',
value: '07', value: '07',
actions: <SemanticsAction>[SemanticsAction.tap], actions: <SemanticsAction>[SemanticsAction.tap],
flags: <SemanticsFlag>[SemanticsFlag.isTextField, SemanticsFlag.isMultiline], flags: <SemanticsFlag>[
SemanticsFlag.isTextField,
SemanticsFlag.hasEnabledState,
SemanticsFlag.isEnabled,
SemanticsFlag.isMultiline,
],
), ),
); );
expect( expect(
...@@ -1352,7 +1357,12 @@ void main() { ...@@ -1352,7 +1357,12 @@ void main() {
label: 'Minute', label: 'Minute',
value: '00', value: '00',
actions: <SemanticsAction>[SemanticsAction.tap], 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() { ...@@ -883,6 +883,7 @@ void main() {
group('simulatedTraversal', () { group('simulatedTraversal', () {
final List<Matcher> fullTraversalMatchers = <Matcher>[ final List<Matcher> fullTraversalMatchers = <Matcher>[
containsSemantics(isHeader: true, label: 'Semantics Test'), containsSemantics(isHeader: true, label: 'Semantics Test'),
containsSemantics(label: 'Text Field'),
containsSemantics(isTextField: true), containsSemantics(isTextField: true),
containsSemantics(label: 'Off Switch'), containsSemantics(label: 'Off Switch'),
containsSemantics(hasToggledState: true), containsSemantics(hasToggledState: true),
...@@ -913,7 +914,7 @@ void main() { ...@@ -913,7 +914,7 @@ void main() {
await tester.pumpWidget(const MaterialApp(home: _SemanticsTestWidget())); await tester.pumpWidget(const MaterialApp(home: _SemanticsTestWidget()));
// We're expecting the traversal to start where the slider is. // 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( expect(
tester.semantics.simulatedAccessibilityTraversal(start: find.byType(Slider)), tester.semantics.simulatedAccessibilityTraversal(start: find.byType(Slider)),
...@@ -988,7 +989,7 @@ void main() { ...@@ -988,7 +989,7 @@ void main() {
await tester.pumpWidget(const MaterialApp(home: _SemanticsTestWidget())); await tester.pumpWidget(const MaterialApp(home: _SemanticsTestWidget()));
// We're expecting the traversal to end where the slider is, inclusive. // 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( expect(
tester.semantics.simulatedAccessibilityTraversal(end: find.byType(Slider)), tester.semantics.simulatedAccessibilityTraversal(end: find.byType(Slider)),
...@@ -1049,7 +1050,7 @@ void main() { ...@@ -1049,7 +1050,7 @@ void main() {
await tester.pumpWidget(const MaterialApp(home: _SemanticsTestWidget())); await tester.pumpWidget(const MaterialApp(home: _SemanticsTestWidget()));
// We're expecting the traversal to start at the text field and end at the slider. // 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( expect(
tester.semantics.simulatedAccessibilityTraversal( tester.semantics.simulatedAccessibilityTraversal(
...@@ -1777,7 +1778,7 @@ class _SemanticsTestWidget extends StatelessWidget { ...@@ -1777,7 +1778,7 @@ class _SemanticsTestWidget extends StatelessWidget {
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
const _SemanticsTestCard( const _SemanticsTestCard(
label: 'TextField', label: 'Text Field',
widget: TextField(), widget: TextField(),
), ),
_SemanticsTestCard( _SemanticsTestCard(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment