Skip to content

Conversation

@hannah-hyj
Copy link
Member

fix: #161628

Pre-launch Checklist

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

@hannah-hyj hannah-hyj requested a review from chunhtai June 16, 2025 22:53
@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. engine flutter/engine related. See also e: labels. a: accessibility Accessibility, e.g. VoiceOver or TalkBack. (aka a11y) platform-web Web applications specifically labels Jun 16, 2025
onWillPop: widget.onWillPop,
child: _FormScope(formState: this, generation: _generation, child: widget.child),
);
return Semantics(role: SemanticsRole.form, child: form);
Copy link
Contributor

Choose a reason for hiding this comment

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

This may need container: true so that it won't merge up and accidentally get other children to be included in the form

Copy link
Contributor

Choose a reason for hiding this comment

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

e.g something like this may break without the container:true here

Semantics(container:true, child: Column(
  children: [Semantics(container: true, child: Text('1')), Form(...)]

))

you will se that text('1') somehow become a child in the form in the semantics tree

semanticsObject,
preferredLabelRepresentation: LabelRepresentation.ariaLabel,
) {
setAriaRole('form');
Copy link
Contributor

Choose a reason for hiding this comment

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

I vaguely remember web use the <form> tag to denote a form, and it is already used somewhere but for other purpose, cc @mdebbar , can you take a look to see if this is ok

Copy link
Member Author

@hannah-hyj hannah-hyj Jun 23, 2025

Choose a reason for hiding this comment

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

I tested using VoiceOver on mac and it does work using ariaRole.

however, https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Roles/form_role also has a warning "Warning: Use an HTML <form> element to contain your form controls, rather than the ARIA form role, unless you have a very good reason. The HTML <form> element is sufficient to tell assistive technologies that there is a form."

@mdebbar do we need to use the form tag or an ariaRole is good enough, wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

"Warning: Use an HTML <form> element to contain your form controls, rather than the ARIA form role, unless you have a very good reason. The HTML <form> element is sufficient to tell assistive technologies that there is a form."

Do we have a "very good reason" to not use the <form> element? 🙂

In the SemanticForm class you could override the createElement method to make it return a <form> element instead of the default. Example:

@override
DomElement createElement() {
final DomElement element = domDocument.createElement('a');
element.style.display = 'block';
return element;
}

I vaguely remember web use the <form> tag to denote a form, and it is already used somewhere but for other purpose, cc @mdebbar , can you take a look to see if this is ok

We do use a form for autofill. But AFAICT, that behavior is disabled when semantics are on:

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you! updated to use the <form> element !

@hannah-hyj hannah-hyj requested a review from mdebbar June 23, 2025 18:03
semanticsObject,
preferredLabelRepresentation: LabelRepresentation.ariaLabel,
) {
setAriaRole('form');
Copy link
Contributor

Choose a reason for hiding this comment

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

"Warning: Use an HTML <form> element to contain your form controls, rather than the ARIA form role, unless you have a very good reason. The HTML <form> element is sufficient to tell assistive technologies that there is a form."

Do we have a "very good reason" to not use the <form> element? 🙂

In the SemanticForm class you could override the createElement method to make it return a <form> element instead of the default. Example:

@override
DomElement createElement() {
final DomElement element = domDocument.createElement('a');
element.style.display = 'block';
return element;
}

I vaguely remember web use the <form> tag to denote a form, and it is already used somewhere but for other purpose, cc @mdebbar , can you take a look to see if this is ok

We do use a form for autofill. But AFAICT, that behavior is disabled when semantics are on:

semantics().semanticsEnabled = false;
}

void _testForms() {
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice to also have a test for this in _testSemanticRole above. Something that checks for:

tester.expectSemantics('''
<sem id="flt-semantic-node-0">
  <form id="flt-semantic-node-1">
    <sem id="flt-semantic-node-2">
      <input />
    </sem>
  </form>
</sem>''');

Copy link
Member Author

Choose a reason for hiding this comment

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

updated tests, thanks!

Copy link
Contributor

@mdebbar mdebbar left a comment

Choose a reason for hiding this comment

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

LGTM if the framework changes LGT @chunhtai

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

Update semantics_test.dart

Update licenses_flutter

Update packages/flutter/lib/src/widgets/form.dart

Update form.dart

Update engine/src/flutter/lib/web_ui/lib/src/engine/semantics/form.dart

Update engine/src/flutter/lib/web_ui/lib/src/engine/semantics/form.dart

Update form.dart

Update form.dart

add tests

lint

Add form role

Co-Authored-By: chunhtai <47866232+chunhtai@users.noreply.github.com>
Co-Authored-By: Mouad Debbar <mouad.debbar@gmail.com>
@hannah-hyj hannah-hyj added the autosubmit Merge PR when tree becomes green via auto submit App label Jul 4, 2025
@auto-submit auto-submit bot added this pull request to the merge queue Jul 4, 2025
Merged via the queue into flutter:master with commit 8edb61a Jul 4, 2025
175 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jul 4, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 4, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 4, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 4, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 7, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 7, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 7, 2025
mboetger pushed a commit to mboetger/flutter that referenced this pull request Jul 21, 2025
fix: [flutter#161628](flutter#161628)
## 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 <47866232+chunhtai@users.noreply.github.com>
Co-authored-by: Mouad Debbar <mouad.debbar@gmail.com>
azatech pushed a commit to azatech/flutter that referenced this pull request Jul 28, 2025
fix: [flutter#161628](flutter#161628)
## 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 <47866232+chunhtai@users.noreply.github.com>
Co-authored-by: Mouad Debbar <mouad.debbar@gmail.com>
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 14, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 14, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 15, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 15, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 16, 2025
lucaantonelli pushed a commit to lucaantonelli/flutter that referenced this pull request Nov 21, 2025
fix: [flutter#161628](flutter#161628)
## 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 <47866232+chunhtai@users.noreply.github.com>
Co-authored-by: Mouad Debbar <mouad.debbar@gmail.com>
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) engine flutter/engine related. See also e: labels. 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.

[a11y] Form should have correct semantics role

3 participants