Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

a11y: expose max character count for text fields#12269

Merged
goderbauer merged 4 commits intoflutter:masterfrom
goderbauer:maxvaluelength
Sep 16, 2019
Merged

a11y: expose max character count for text fields#12269
goderbauer merged 4 commits intoflutter:masterfrom
goderbauer:maxvaluelength

Conversation

@goderbauer
Copy link
Member

Wire up Android's setMaxTextLength to communicate the number of characters a user can input into a text field to a11y users.

Work towards flutter/flutter#38940

@goderbauer goderbauer changed the title a11y: add max character count for text fields a11y: expose max character count for text fields Sep 13, 2019
}
result.setMovementGranularities(granularities);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && semanticsNode.maxValueLength != -1) {
result.setMaxTextLength(semanticsNode.maxValueLength);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please double check the behavior here with non-english texts + emojis. We might need to massage the data from codePoints to graphemes or characters

Copy link
Member Author

Choose a reason for hiding this comment

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

Of course this is complicated: Flutter expresses its character count as number of Unicode scalar values that are allowed (which has its own limitations, see https://master-api.flutter.dev/flutter/material/TextField/maxLength.html). Android on the other hand encodes the content of the text field with utf16 and counts the number of bytes. So the American Flag emoji has a length of 2 in Flutter, but a length of 4 for Android. A regular human being would probably consider that thing to just be one character...

Anyways, not sure how to resolve this. I'll do some more research.

Copy link
Contributor

Choose a reason for hiding this comment

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

I thought about this some more. I think we really want to avoid the situation where the character counter on the flutter side is wildly out of sync with the character counter on the native side. It sounds like this would be the case with this change and there isn't much we can do about it, given that we don't control how Android/Talkback count characters.

Copy link
Contributor

Choose a reason for hiding this comment

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

unless of course we could either trick Android into thinking we had a specific number of characters, or adjusted our character count to be (more?) broken

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 added another property "currentValueLength" which contains what the framework currently things the length of the entered text is. I am using this one to adjust the max value if android and flutter disagree on the size of the text. While the max value reported to android can now change depending on the characters you enter, it works great with talkback and talkback announces at the correct point that the maximum has been reached.

Copy link
Contributor

Choose a reason for hiding this comment

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

🎊

/// string describes what result an action performed on this node has. The
/// reading direction of all these strings is given by `textDirection`.
///
/// The fields 'textSelectionBase' and 'textSelectionExtent' describe the
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to be added to the web_ui implementation too

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

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

LGTM

@goderbauer goderbauer merged commit ef7bcaf into flutter:master Sep 16, 2019
@goderbauer goderbauer deleted the maxvaluelength branch September 16, 2019 16:37
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 16, 2019
engine-flutter-autoroll added a commit to flutter/flutter that referenced this pull request Sep 16, 2019
[email protected]:flutter/engine.git/compare/04f567bdde40...2c4ed36

git log 04f567b..2c4ed36 --no-merges --oneline
2019-09-16 [email protected] Roll src/third_party/dart a8f433820b..7799f424f4 (3 commits)
2019-09-16 [email protected] a11y: expose max character count for text fields (flutter/engine#12269)
2019-09-16 [email protected] Roll src/third_party/skia 86c48abc94f3..c22498502cda (1 commits) (flutter/engine#12300)


If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC [email protected] on the revert to ensure that a human
is aware of the problem.

To report a problem with the AutoRoller itself, please file a bug:
https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md
Inconnu08 pushed a commit to Inconnu08/flutter that referenced this pull request Sep 30, 2019
[email protected]:flutter/engine.git/compare/04f567bdde40...2c4ed36

git log 04f567b..2c4ed36 --no-merges --oneline
2019-09-16 [email protected] Roll src/third_party/dart a8f433820b..7799f424f4 (3 commits)
2019-09-16 [email protected] a11y: expose max character count for text fields (flutter/engine#12269)
2019-09-16 [email protected] Roll src/third_party/skia 86c48abc94f3..c22498502cda (1 commits) (flutter/engine#12300)


If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC [email protected] on the revert to ensure that a human
is aware of the problem.

To report a problem with the AutoRoller itself, please file a bug:
https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants