Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[a11y] add SemanticsValidationResult #165935

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

Merged
merged 2 commits into from
Apr 2, 2025
Merged

Conversation

yjbanov
Copy link
Contributor

@yjbanov yjbanov commented Mar 26, 2025

Add SemanticsValidationResult to semantics that maps onto aria-invalid.

Fixes #162142

@github-actions github-actions bot added a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. engine flutter/engine repository. See also e: labels. a: accessibility Accessibility, e.g. VoiceOver or TalkBack. (aka a11y) platform-web Web applications specifically a: tests "flutter test", flutter_test, or one of our tests f: material design flutter/packages/flutter/material repository. labels Mar 26, 2025
@yjbanov yjbanov requested a review from chunhtai March 27, 2025 22:34
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.

I think the approach looks fine for the form widget. We have been relying on implicit merging to supplement semantics in container widget like this.

/// If [validationResult] is null, removes the `aria-invalid` attribute from
/// the element.
static void updateAriaInvalid(DomElement element, ui.SemanticsValidationResult validationResult) {
if (validationResult != ui.SemanticsValidationResult.none) {
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 use switch case in case someone add a different enum in other platform without knowing how it is used here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. I inlined the switch from toAriaValue here. That was a bit of an overarchitecture.

/// the element.
static void updateAriaInvalid(DomElement element, ui.SemanticsValidationResult validationResult) {
if (validationResult != ui.SemanticsValidationResult.none) {
element.setAttribute('aria-invalid', validationResult.toAriaValue());
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, I should scroll it down further. thanks

// reversed.
return 'true';
case ui.SemanticsValidationResult.grammar:
return 'grammar';
Copy link
Contributor

Choose a reason for hiding this comment

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

does aria-invalid='grammar' actually work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It works in the sense that the screen reader still reads "invalid entry", but as of today all screen readers I tested on the result is no different from just doing aria-invalid="true".

@@ -3057,3 +3107,30 @@ enum EnabledState {
/// The node is disabled.
disabled,
}

extension SemanticsValidationResultExtension on ui.SemanticsValidationResult {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does this use an extension instead of directly in the enum class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The enum class is public. We don't want web-specific details to be published through dart:ui types. However, this is gone now. Originally, I had toAriaValue used in multiple places, but then collapsed it to one, so I don't need it to be a shared function anymore.

@@ -3076,6 +3128,10 @@ class SemanticsNode with DiagnosticableTreeMixin {
Set<String>? get controlsNodes => _controlsNodes;
Set<String>? _controlsNodes = _kEmptyConfig.controlsNodes;

/// {@macro flutter.semantics.SemanticsProperties.validationResult}
SemanticsValidationResult get validationResult => _validationResult;
SemanticsValidationResult _validationResult = SemanticsValidationResult.none;
Copy link
Contributor

Choose a reason for hiding this comment

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

_kEmptyConfig.validationResult is safer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -5778,6 +5857,11 @@ class SemanticsConfiguration {
_controlsNodes = <String>{..._controlsNodes!, ...child._controlsNodes!};
}

if (_validationResult == SemanticsValidationResult.none &&
child._validationResult != _validationResult) {
Copy link
Contributor

Choose a reason for hiding this comment

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

should we do some kind of prioritize invalid similar to the getSemanticsData

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not even sure screen readers would support nested validation results. So maybe we should assert and throw if conflicting validation results are being merged?

Copy link
Contributor

Choose a reason for hiding this comment

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

probably shouldn't throw. we can either generate separate node or have some merging strategy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Merged with invalid taking precedence.

@yjbanov yjbanov marked this pull request as ready for review March 28, 2025 21:39
@yjbanov yjbanov requested a review from chunhtai March 28, 2025 22:27
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, just some questions

// 'false' may seem counter-intuitive for a "valid" result, but it's
// because the ARIA attribute is `aria-invalid`, so its value is
// reversed.
element.setAttribute('aria-invalid', 'false');
Copy link
Contributor

Choose a reason for hiding this comment

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

will there be a different between aria-invalid="false" vs not providing aria-invalid at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't not see a difference in the screen reader behavior.

@yjbanov yjbanov added the autosubmit Merge PR when tree becomes green via auto submit App label Apr 2, 2025
@auto-submit auto-submit bot added this pull request to the merge queue Apr 2, 2025
@matanlurey matanlurey removed this pull request from the merge queue due to a manual request Apr 2, 2025
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Apr 2, 2025
@matanlurey matanlurey added this pull request to the merge queue Apr 2, 2025
@matanlurey matanlurey removed this pull request from the merge queue due to a manual request Apr 2, 2025
@matanlurey matanlurey added this pull request to the merge queue Apr 2, 2025
@matanlurey matanlurey removed this pull request from the merge queue due to a manual request Apr 2, 2025
@yjbanov yjbanov added the autosubmit Merge PR when tree becomes green via auto submit App label Apr 2, 2025
@auto-submit auto-submit bot added this pull request to the merge queue Apr 2, 2025
Merged via the queue into flutter:master with commit fbbe0f9 Apr 2, 2025
174 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Apr 2, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 3, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 3, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 3, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 3, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 3, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 3, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 3, 2025
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Apr 3, 2025
Roll Flutter from a0b1b3253416 to 02f13c37841f (37 revisions)

flutter/flutter@a0b1b32...02f13c3

2025-04-03 [email protected] Roll Packages from 07496eb to 4a36dc6 (3 revisions) (flutter/flutter#166542)
2025-04-03 [email protected] Roll Skia from b67e53719e78 to 5f65df75febd (2 revisions) (flutter/flutter#166538)
2025-04-03 [email protected] Update docs to debug the Android embedder (flutter/flutter#166170)
2025-04-03 [email protected] Roll Dart SDK from 72562ca93bb5 to d174ec16c3ea (1 revision) (flutter/flutter#166525)
2025-04-03 [email protected] [macOS] Implement merged UI and platform thread (flutter/flutter#162883)
2025-04-03 [email protected] Roll Skia from f91412f5d89d to b67e53719e78 (1 revision) (flutter/flutter#166527)
2025-04-03 [email protected] Roll Packages from 125c117 to 07496eb (31 revisions) (flutter/flutter#166457)
2025-04-03 [email protected] Roll Skia from 2be12bc2668b to f91412f5d89d (2 revisions) (flutter/flutter#166517)
2025-04-03 [email protected] Roll Dart SDK from 2a1a13cc3a91 to 72562ca93bb5 (2 revisions) (flutter/flutter#166514)
2025-04-03 [email protected] [native_assets] Roll dependencies (flutter/flutter#166282)
2025-04-03 [email protected] Fix read only TextField focus traversal on macOS (flutter/flutter#166056)
2025-04-03 [email protected] Roll Skia from c106d7831592 to 2be12bc2668b (1 revision) (flutter/flutter#166509)
2025-04-03 [email protected] Roll Fuchsia Linux SDK from v7PGvypiiWLO8PbsZ... to vYisSsIgqw0mqFRVJ... (flutter/flutter#166508)
2025-04-03 [email protected] Roll Dart SDK from b8b4076b1237 to 2a1a13cc3a91 (1 revision) (flutter/flutter#166504)
2025-04-03 [email protected] Roll Skia from 75a0ec473181 to c106d7831592 (1 revision) (flutter/flutter#166499)
2025-04-03 [email protected] Migrate to Theme.brightnessOf method (flutter/flutter#163950)
2025-04-03 [email protected] Fix: Range slider show overlay for both thumbs on hovering one (flutter/flutter#165393)
2025-04-03 [email protected] Deprecate ExpansionTileController (flutter/flutter#166368)
2025-04-03 [email protected] Add styling parameters in `PopupMenuDivider` (flutter/flutter#164790)
2025-04-03 [email protected] Fix ISSUE_TEMPLATE Ordering: `10 < 9`, but `10 > 09` (flutter/flutter#166455)
2025-04-03 [email protected] Skip flaking scheduler test (flutter/flutter#166471)
2025-04-02 [email protected] Roll pub packages (flutter/flutter#166043)
2025-04-02 [email protected] [a11y] add SemanticsValidationResult (flutter/flutter#165935)
2025-04-02 [email protected] Remove unnecessary cache busting mechanism in hot restart (flutter/flutter#166295)
2025-04-02 [email protected] Roll Skia from 52cbb917fffd to 75a0ec473181 (21 revisions) (flutter/flutter#166484)
2025-04-02 [email protected] Started pixel aligning hairlines (flutter/flutter#166351)
2025-04-02 [email protected] Adds semantics role and adjust semantics for navigation bar (flutter/flutter#162467)
2025-04-02 [email protected] Reland "[skwasm] Dynamic Threading" (flutter/flutter#166454)
2025-04-02 [email protected] [dart:ui] Add `Path.addRSuperellipse` (flutter/flutter#166045)
2025-04-02 [email protected] Fix: Hero animation for page transition (flutter/flutter#164469)
2025-04-02 [email protected] Fix: DelegateTransition for cupertino sheet route (flutter/flutter#164675)
2025-04-02 [email protected] Roll Fuchsia Test Scripts from AEdsljKmUiPk92Wvv... to FZdRtNwH7jmADecj6... (flutter/flutter#166383)
2025-04-02 [email protected] [Impeller] cache for text shadows. (flutter/flutter#166228)
2025-04-02 [email protected] Convert `AppPluginLoaderPlugin` to Kotlin, and add `NativePluginLoaderReflectionBridge` to expose it in Kotlin (flutter/flutter#166027)
2025-04-02 [email protected] Roll Dart SDK from 4e1f02bc704f to b8b4076b1237 (7 revisions) (flutter/flutter#166474)
2025-04-02 [email protected] Update Roadmap (flutter/flutter#166332)
2025-04-02 [email protected] Update `CODEOWNERS` (flutter/flutter#166444)

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

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

...
CodixNinja pushed a commit to CodixNinja/packages that referenced this pull request May 15, 2025
Roll Flutter from a0b1b3253416 to 02f13c37841f (37 revisions)

flutter/flutter@a0b1b32...02f13c3

2025-04-03 [email protected] Roll Packages from d10d5af to 95f8e65 (3 revisions) (flutter/flutter#166542)
2025-04-03 [email protected] Roll Skia from b67e53719e78 to 5f65df75febd (2 revisions) (flutter/flutter#166538)
2025-04-03 [email protected] Update docs to debug the Android embedder (flutter/flutter#166170)
2025-04-03 [email protected] Roll Dart SDK from 72562ca93bb5 to d174ec16c3ea (1 revision) (flutter/flutter#166525)
2025-04-03 [email protected] [macOS] Implement merged UI and platform thread (flutter/flutter#162883)
2025-04-03 [email protected] Roll Skia from f91412f5d89d to b67e53719e78 (1 revision) (flutter/flutter#166527)
2025-04-03 [email protected] Roll Packages from 0d5d57b to d10d5af (31 revisions) (flutter/flutter#166457)
2025-04-03 [email protected] Roll Skia from 2be12bc2668b to f91412f5d89d (2 revisions) (flutter/flutter#166517)
2025-04-03 [email protected] Roll Dart SDK from 2a1a13cc3a91 to 72562ca93bb5 (2 revisions) (flutter/flutter#166514)
2025-04-03 [email protected] [native_assets] Roll dependencies (flutter/flutter#166282)
2025-04-03 [email protected] Fix read only TextField focus traversal on macOS (flutter/flutter#166056)
2025-04-03 [email protected] Roll Skia from c106d7831592 to 2be12bc2668b (1 revision) (flutter/flutter#166509)
2025-04-03 [email protected] Roll Fuchsia Linux SDK from v7PGvypiiWLO8PbsZ... to vYisSsIgqw0mqFRVJ... (flutter/flutter#166508)
2025-04-03 [email protected] Roll Dart SDK from b8b4076b1237 to 2a1a13cc3a91 (1 revision) (flutter/flutter#166504)
2025-04-03 [email protected] Roll Skia from 75a0ec473181 to c106d7831592 (1 revision) (flutter/flutter#166499)
2025-04-03 [email protected] Migrate to Theme.brightnessOf method (flutter/flutter#163950)
2025-04-03 [email protected] Fix: Range slider show overlay for both thumbs on hovering one (flutter/flutter#165393)
2025-04-03 [email protected] Deprecate ExpansionTileController (flutter/flutter#166368)
2025-04-03 [email protected] Add styling parameters in `PopupMenuDivider` (flutter/flutter#164790)
2025-04-03 [email protected] Fix ISSUE_TEMPLATE Ordering: `10 < 9`, but `10 > 09` (flutter/flutter#166455)
2025-04-03 [email protected] Skip flaking scheduler test (flutter/flutter#166471)
2025-04-02 [email protected] Roll pub packages (flutter/flutter#166043)
2025-04-02 [email protected] [a11y] add SemanticsValidationResult (flutter/flutter#165935)
2025-04-02 [email protected] Remove unnecessary cache busting mechanism in hot restart (flutter/flutter#166295)
2025-04-02 [email protected] Roll Skia from 52cbb917fffd to 75a0ec473181 (21 revisions) (flutter/flutter#166484)
2025-04-02 [email protected] Started pixel aligning hairlines (flutter/flutter#166351)
2025-04-02 [email protected] Adds semantics role and adjust semantics for navigation bar (flutter/flutter#162467)
2025-04-02 [email protected] Reland "[skwasm] Dynamic Threading" (flutter/flutter#166454)
2025-04-02 [email protected] [dart:ui] Add `Path.addRSuperellipse` (flutter/flutter#166045)
2025-04-02 [email protected] Fix: Hero animation for page transition (flutter/flutter#164469)
2025-04-02 [email protected] Fix: DelegateTransition for cupertino sheet route (flutter/flutter#164675)
2025-04-02 [email protected] Roll Fuchsia Test Scripts from AEdsljKmUiPk92Wvv... to FZdRtNwH7jmADecj6... (flutter/flutter#166383)
2025-04-02 [email protected] [Impeller] cache for text shadows. (flutter/flutter#166228)
2025-04-02 [email protected] Convert `AppPluginLoaderPlugin` to Kotlin, and add `NativePluginLoaderReflectionBridge` to expose it in Kotlin (flutter/flutter#166027)
2025-04-02 [email protected] Roll Dart SDK from 4e1f02bc704f to b8b4076b1237 (7 revisions) (flutter/flutter#166474)
2025-04-02 [email protected] Update Roadmap (flutter/flutter#166332)
2025-04-02 [email protected] Update `CODEOWNERS` (flutter/flutter#166444)

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

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

...
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 20, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 20, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 21, 2025
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: tests "flutter test", flutter_test, or one of our tests a: text input Entering text in a text field or keyboard related problems engine flutter/engine repository. See also e: labels. f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. platform-web Web applications specifically
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Flutter Web: aria-invalid must be an available property on form inputs (Accessibility)
2 participants