Skip to content

Commit 35375e4

Browse files
hannah-hyjchunhtai
andauthored
[a11y] : set isFocused will update isFocusable to true (flutter#170935)
the isFocused and isFocusable flags should be more consistent, this is also to prepare for flutter#170696 , So all EditableText and TextField widgets will have isFocusable flag set to true now. (because they set isFocused). ## Pre-launch Checklist - [ ] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [ ] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [ ] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [ ] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [ ] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md --------- Co-authored-by: chunhtai <[email protected]>
1 parent 2c031ed commit 35375e4

File tree

5 files changed

+33
-7
lines changed

5 files changed

+33
-7
lines changed

packages/flutter/lib/src/rendering/custom_paint.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ class RenderCustomPaint extends RenderProxyBox {
953953
config.isFocusable = properties.focusable!;
954954
}
955955
if (properties.focused != null) {
956-
config.isFocused = properties.focused!;
956+
config.isFocused = properties.focused;
957957
}
958958
if (properties.enabled != null) {
959959
config.isEnabled = properties.enabled;

packages/flutter/lib/src/rendering/object.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4857,7 +4857,7 @@ mixin SemanticsAnnotationsMixin on RenderObject {
48574857
config.isFocusable = _properties.focusable!;
48584858
}
48594859
if (_properties.focused != null) {
4860-
config.isFocused = _properties.focused!;
4860+
config.isFocused = _properties.focused;
48614861
}
48624862
if (_properties.inMutuallyExclusiveGroup != null) {
48634863
config.isInMutuallyExclusiveGroup = _properties.inMutuallyExclusiveGroup!;

packages/flutter/lib/src/semantics/semantics.dart

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,6 +1472,11 @@ class SemanticsProperties extends DiagnosticableTree {
14721472
this.slider,
14731473
this.keyboardKey,
14741474
this.readOnly,
1475+
@Deprecated(
1476+
'Use focused instead. '
1477+
'Setting focused automatically set focusable. '
1478+
'This feature was deprecated after v3.36.0-0.0.pre.',
1479+
)
14751480
this.focusable,
14761481
this.focused,
14771482
this.inMutuallyExclusiveGroup,
@@ -1656,10 +1661,17 @@ class SemanticsProperties extends DiagnosticableTree {
16561661
/// to be confused with accessibility focus. Accessibility focus is the
16571662
/// green/black rectangular highlight that TalkBack/VoiceOver draws around the
16581663
/// element it is reading, and is separate from input focus.
1664+
@Deprecated(
1665+
'Use focused instead. '
1666+
'Setting focused automatically set focusable. '
1667+
'This feature was deprecated after v3.36.0-0.0.pre.',
1668+
)
16591669
final bool? focusable;
16601670

16611671
/// If non-null, whether the node currently holds input focus.
16621672
///
1673+
/// If null, the node is not fosusable.
1674+
///
16631675
/// At most one node in the tree should hold input focus at any point in time,
16641676
/// and it should not be set to true if [focusable] is false.
16651677
///
@@ -5589,16 +5601,30 @@ class SemanticsConfiguration {
55895601
}
55905602

55915603
/// Whether the owning [RenderObject] can hold the input focus.
5604+
@Deprecated(
5605+
'Check if isFocused is null instead. '
5606+
'This feature was deprecated after v3.36.0-0.0.pre.',
5607+
)
55925608
bool get isFocusable => _flags.isFocusable;
5609+
5610+
@Deprecated(
5611+
'Setting isFocused automatically set this to true. '
5612+
'This feature was deprecated after v3.36.0-0.0.pre.',
5613+
)
55935614
set isFocusable(bool value) {
55945615
_flags = _flags.copyWith(isFocusable: value);
55955616
_hasBeenAnnotated = true;
55965617
}
55975618

55985619
/// Whether the owning [RenderObject] currently holds the input focus.
5599-
bool get isFocused => _flags.isFocused;
5600-
set isFocused(bool value) {
5601-
_flags = _flags.copyWith(isFocused: value);
5620+
/// If the value is `null`, it's not focusable.
5621+
bool? get isFocused => _flags.isFocusable ? _flags.isFocused : null;
5622+
set isFocused(bool? value) {
5623+
if (value != null) {
5624+
_flags = _flags.copyWith(isFocusable: true, isFocused: value);
5625+
} else {
5626+
_flags = _flags.copyWith(isFocusable: false, isFocused: false);
5627+
}
56025628
_hasBeenAnnotated = true;
56035629
}
56045630

packages/flutter/lib/src/widgets/focus_scope.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ class _FocusState extends State<Focus> {
724724
? focusNode.requestFocus
725725
: null,
726726
focusable: _couldRequestFocus,
727-
focused: _hadPrimaryFocus,
727+
focused: _couldRequestFocus ? _hadPrimaryFocus : null,
728728
child: widget.child,
729729
);
730730
}

packages/flutter/test/semantics/semantics_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ void main() {
937937
expect(config.isChecked, null);
938938
expect(config.isSelected, isFalse);
939939
expect(config.isBlockingSemanticsOfPreviouslyPaintedNodes, isFalse);
940-
expect(config.isFocused, isFalse);
940+
expect(config.isFocused, null);
941941
expect(config.isTextField, isFalse);
942942

943943
expect(config.onShowOnScreen, isNull);

0 commit comments

Comments
 (0)