Request focus if SemanticsAction.focus is sent to a focusable widget (#142942)
## Description This causes the `Focus` widget to request focus on its focus node if the accessibility system (screen reader) focuses a widget via the `SemanticsAction.focus` action. ## Related Issues - https://github.com/flutter/flutter/issues/83809 ## Tests - Added a test to make sure that focus is requested when `SemanticsAction.focus` is sent by the engine.
This commit is contained in:
@@ -674,6 +674,7 @@ Matcher matchesSemantics({
|
||||
bool isExpanded = false,
|
||||
// Actions //
|
||||
bool hasTapAction = false,
|
||||
bool hasFocusAction = false,
|
||||
bool hasLongPressAction = false,
|
||||
bool hasScrollLeftAction = false,
|
||||
bool hasScrollRightAction = false,
|
||||
@@ -753,6 +754,7 @@ Matcher matchesSemantics({
|
||||
isExpanded: isExpanded,
|
||||
// Actions
|
||||
hasTapAction: hasTapAction,
|
||||
hasFocusAction: hasFocusAction,
|
||||
hasLongPressAction: hasLongPressAction,
|
||||
hasScrollLeftAction: hasScrollLeftAction,
|
||||
hasScrollRightAction: hasScrollRightAction,
|
||||
@@ -860,6 +862,7 @@ Matcher containsSemantics({
|
||||
bool? isExpanded,
|
||||
// Actions
|
||||
bool? hasTapAction,
|
||||
bool? hasFocusAction,
|
||||
bool? hasLongPressAction,
|
||||
bool? hasScrollLeftAction,
|
||||
bool? hasScrollRightAction,
|
||||
@@ -939,6 +942,7 @@ Matcher containsSemantics({
|
||||
isExpanded: isExpanded,
|
||||
// Actions
|
||||
hasTapAction: hasTapAction,
|
||||
hasFocusAction: hasFocusAction,
|
||||
hasLongPressAction: hasLongPressAction,
|
||||
hasScrollLeftAction: hasScrollLeftAction,
|
||||
hasScrollRightAction: hasScrollRightAction,
|
||||
@@ -2259,6 +2263,7 @@ class _MatchesSemanticsData extends Matcher {
|
||||
required bool? isExpanded,
|
||||
// Actions
|
||||
required bool? hasTapAction,
|
||||
required bool? hasFocusAction,
|
||||
required bool? hasLongPressAction,
|
||||
required bool? hasScrollLeftAction,
|
||||
required bool? hasScrollRightAction,
|
||||
@@ -2317,6 +2322,7 @@ class _MatchesSemanticsData extends Matcher {
|
||||
},
|
||||
actions = <SemanticsAction, bool>{
|
||||
if (hasTapAction != null) SemanticsAction.tap: hasTapAction,
|
||||
if (hasFocusAction != null) SemanticsAction.focus: hasFocusAction,
|
||||
if (hasLongPressAction != null) SemanticsAction.longPress: hasLongPressAction,
|
||||
if (hasScrollLeftAction != null) SemanticsAction.scrollLeft: hasScrollLeftAction,
|
||||
if (hasScrollRightAction != null) SemanticsAction.scrollRight: hasScrollRightAction,
|
||||
@@ -2379,8 +2385,8 @@ class _MatchesSemanticsData extends Matcher {
|
||||
final Map<SemanticsFlag, bool> flags;
|
||||
|
||||
@override
|
||||
Description describe(Description description) {
|
||||
description.add('has semantics');
|
||||
Description describe(Description description, [String? index]) {
|
||||
description.add('${index == null ? '' : 'Child $index '}has semantics');
|
||||
if (label != null) {
|
||||
description.add(' with label: $label');
|
||||
}
|
||||
@@ -2479,9 +2485,15 @@ class _MatchesSemanticsData extends Matcher {
|
||||
description.add(' with custom hints: $hintOverrides');
|
||||
}
|
||||
if (children != null) {
|
||||
description.add(' with children:\n');
|
||||
for (final _MatchesSemanticsData child in children!.cast<_MatchesSemanticsData>()) {
|
||||
child.describe(description);
|
||||
description.add(' with children:\n ');
|
||||
final List<_MatchesSemanticsData> childMatches = children!.cast<_MatchesSemanticsData>();
|
||||
int childIndex = 1;
|
||||
for (final _MatchesSemanticsData child in childMatches) {
|
||||
child.describe(description, index != null ? '$index:$childIndex': '$childIndex');
|
||||
if (child != childMatches.last) {
|
||||
description.add('\n ');
|
||||
}
|
||||
childIndex += 1;
|
||||
}
|
||||
}
|
||||
return description;
|
||||
|
||||
@@ -746,6 +746,7 @@ void main() {
|
||||
hasDidGainAccessibilityFocusAction: true,
|
||||
hasDidLoseAccessibilityFocusAction: true,
|
||||
hasDismissAction: true,
|
||||
hasFocusAction: true,
|
||||
customActions: <CustomSemanticsAction>[action],
|
||||
));
|
||||
});
|
||||
@@ -1033,6 +1034,7 @@ void main() {
|
||||
hasDidGainAccessibilityFocusAction: true,
|
||||
hasDidLoseAccessibilityFocusAction: true,
|
||||
hasDismissAction: true,
|
||||
hasFocusAction: true,
|
||||
customActions: <CustomSemanticsAction>[action],
|
||||
),
|
||||
);
|
||||
@@ -1125,6 +1127,7 @@ void main() {
|
||||
hasDidGainAccessibilityFocusAction: false,
|
||||
hasDidLoseAccessibilityFocusAction: false,
|
||||
hasDismissAction: false,
|
||||
hasFocusAction: false,
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user