Unverified Commit e6f2bc86 authored by William Oprandi's avatar William Oprandi Committed by GitHub

FocusableActionDetector now exposes descendantsAreFocusable property (#77288)

parent b35fbfec
......@@ -1246,6 +1246,7 @@ class FocusableActionDetector extends StatefulWidget {
this.enabled = true,
this.focusNode,
this.autofocus = false,
this.descendantsAreFocusable = true,
this.shortcuts,
this.actions,
this.onShowFocusHighlight,
......@@ -1274,6 +1275,9 @@ class FocusableActionDetector extends StatefulWidget {
/// {@macro flutter.widgets.Focus.autofocus}
final bool autofocus;
/// {@macro flutter.widgets.Focus.descendantsAreFocusable}
final bool descendantsAreFocusable;
/// {@macro flutter.widgets.actions.actions}
final Map<Type, Action<Intent>>? actions;
......@@ -1459,6 +1463,7 @@ class _FocusableActionDetectorState extends State<FocusableActionDetector> {
child: Focus(
focusNode: widget.focusNode,
autofocus: widget.autofocus,
descendantsAreFocusable: widget.descendantsAreFocusable,
canRequestFocus: _canRequestFocus,
onFocusChange: _handleFocusChange,
child: widget.child,
......
......@@ -919,6 +919,50 @@ void main() {
expect(hovering, isFalse);
expect(focusing, isFalse);
});
testWidgets(
'FocusableActionDetector can prevent its descendants from being focusable',
(WidgetTester tester) async {
final FocusNode buttonNode = FocusNode(debugLabel: 'Test');
await tester.pumpWidget(
MaterialApp(
home: FocusableActionDetector(
descendantsAreFocusable: true,
child: MaterialButton(
focusNode: buttonNode,
child: const Text('Test'),
onPressed: () {},
),
),
),
);
// Button is focusable
expect(buttonNode.hasFocus, isFalse);
buttonNode.requestFocus();
await tester.pump();
expect(buttonNode.hasFocus, isTrue);
await tester.pumpWidget(
MaterialApp(
home: FocusableActionDetector(
descendantsAreFocusable: false,
child: MaterialButton(
focusNode: buttonNode,
child: const Text('Test'),
onPressed: () {},
),
),
),
);
// Button is NOT focusable
expect(buttonNode.hasFocus, isFalse);
buttonNode.requestFocus();
await tester.pump();
expect(buttonNode.hasFocus, isFalse);
});
});
group('Diagnostics', () {
......
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