mirror of
https://github.com/flutter/flutter
synced 2024-10-03 23:14:12 +00:00
FocusableActionDetector now exposes descendantsAreFocusable property (#77288)
This commit is contained in:
parent
b35fbfec1d
commit
e6f2bc8637
|
@ -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', () {
|
||||
|
|
Loading…
Reference in a new issue