这是indexloc提供的服务,不要输入任何密码
Skip to content

[a11y] : set isFocused will update isFocusable to true #170935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hannah-hyj
Copy link
Member

@hannah-hyj hannah-hyj commented Jun 20, 2025

the isFocused and isFocusable flags should be more consistent,

this is also to prepare for #170696 ,

So all EditableText and TextField widgets will have isFocusable flag set to true now. (because they set isFocused).

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard

This comment was marked as outdated.

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. a: accessibility Accessibility, e.g. VoiceOver or TalkBack. (aka a11y) f: focus Focus traversal, gaining or losing focus labels Jun 20, 2025
@hannah-hyj hannah-hyj changed the title [draft] : set isFocused will update isFocusable to true [a11y] : set isFocused will update isFocusable to true Jun 25, 2025
@github-actions github-actions bot added a: tests "flutter test", flutter_test, or one of our tests a: text input Entering text in a text field or keyboard related problems f: material design flutter/packages/flutter/material repository. f: cupertino flutter/packages/flutter/cupertino repository labels Jun 25, 2025
@hannah-hyj hannah-hyj requested a review from chunhtai June 25, 2025 06:24
@github-actions github-actions bot removed the a: tests "flutter test", flutter_test, or one of our tests label Jun 25, 2025
@hannah-hyj hannah-hyj force-pushed the isfocusable-and-isfocused branch from 376de89 to 5408de2 Compare June 25, 2025 18:04
@hannah-hyj hannah-hyj force-pushed the isfocusable-and-isfocused branch from ed7ed86 to e823d05 Compare June 26, 2025 20:13
@hannah-hyj hannah-hyj requested a review from chunhtai June 26, 2025 20:25
Copy link
Contributor

@chunhtai chunhtai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we also need to add a migration guide

_flags = _flags.copyWith(isFocused: value);
bool? get isFocused => _flags.isFocusable ? _flags.isFocused : null;
set isFocused(bool? value) {
if (value != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is null, should this reset isFocusable? I looked at other property looks like they just pass the null to the flags, not sure if those make sense neither

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated this to reset isFocusable to false if this is null, i think it makes more sense to me.

@@ -955,7 +955,7 @@ class RenderCustomPaint extends RenderProxyBox {
config.isFocusable = properties.focusable!;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should attempt to migrate this, the focusable in SemanticsProperty should be deprecated as well

@hannah-hyj hannah-hyj requested a review from chunhtai June 27, 2025 20:13
@hannah-hyj
Copy link
Member Author

PR to add breaking changes doc flutter/website#12159

}
if (properties.focused != null) {
config.isFocused = properties.focused!;
if (properties.focusable != null ||properties.focused != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not formatted correctly

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this for backward compatibility? why do we need to check for focusable?

Copy link
Member Author

@hannah-hyj hannah-hyj Jun 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was for backward compatibility but yeah this should be updated

previously, properties.focused== null means the properties don't have a meaningful value for focused , now it explicitly means this semantics node is not focusable. So the config.focused should be updated even if properties.focused is null. but if we always update config.focused , the _hasBeenAnnotated in semanticsNode might be messed up and the tree structure will change.

Copy link
Member Author

@hannah-hyj hannah-hyj Jul 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discussed offline, the tree structure changes are intended, for example the dropdown menu will lose a semantic node but the node contains no information.
Screenshot 2025-07-01 at 18 24 47

@@ -726,7 +726,7 @@ class _FocusState extends State<Focus> {
? focusNode.requestFocus
: null,
focusable: _couldRequestFocus,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should remove any invocation to the deprecated property

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like Semantics(focusable) is not deprecated. is there a reason we want to keep it around?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah i should remove this, my mistake

@hannah-hyj hannah-hyj requested a review from chunhtai July 2, 2025 02:23
Copy link
Contributor

@chunhtai chunhtai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Deprecated(
'Setting isFocused automatically set this to true. '
'This feature was deprecated after v3.34.0-0.0.pre.',
)
set isFocusable(bool value) {
_flags = _flags.copyWith(isFocusable: value);
_hasBeenAnnotated = true;
}

/// Whether the owning [RenderObject] currently holds the input focus.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the doc around isFocused should mention null if this is not focusable

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here and elsewhere

@@ -3815,11 +3815,12 @@ void main() {
await tester.pumpWidget(buildDropdownMenu(requestFocusOnTap: true));

expect(
tester.getSemantics(find.byType(TextField)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change?

Copy link
Member Author

@hannah-hyj hannah-hyj Jul 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2025-07-02 at 10 32 18

The semantics tree structure didn't change after my PR. Only the isFocusable flag value is changed. however, tester.getSemantics(find.byType(TextField)) will find the node 3 : scopeRoute. tester.getSemantics(find.text('Test')) will find the node 5

@hannah-hyj hannah-hyj force-pushed the isfocusable-and-isfocused branch 2 times, most recently from 7a2c556 to 46f29bb Compare July 7, 2025 21:48
@hannah-hyj hannah-hyj force-pushed the isfocusable-and-isfocused branch from 46f29bb to 790c6c1 Compare July 11, 2025 21:00
@hannah-hyj
Copy link
Member Author

hannah-hyj commented Jul 11, 2025

This PR is failing dozens of google 3 tests , some because textfield now have isFocusable flags, some because of other reasons, i'm still fixing google 3 tests.

isfocusable changes

revert inkwell changes

isfocusable changes

Update ink_well.dart

Update semantics.dart

lint

Update shortcuts_test.dart

fix tests

test

resolve comments

fix tests

Update semantics.dart

fix tests

resolve comments

Update semantics.dart

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

mark Deprecated

Update semantics_test.dart

update more tests

fix tests

updates

lint

Update semantics.dart

Update semantics.dart

Update semantics.dart

Co-Authored-By: chunhtai <47866232+chunhtai@users.noreply.github.com>
@hannah-hyj hannah-hyj force-pushed the isfocusable-and-isfocused branch from e63ff63 to 9341156 Compare July 21, 2025 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: accessibility Accessibility, e.g. VoiceOver or TalkBack. (aka a11y) a: text input Entering text in a text field or keyboard related problems f: cupertino flutter/packages/flutter/cupertino repository f: focus Focus traversal, gaining or losing focus f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants