-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Add semantics role for form #170709
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
Add semantics role for form #170709
Conversation
| onWillPop: widget.onWillPop, | ||
| child: _FormScope(formState: this, generation: _generation, child: widget.child), | ||
| ); | ||
| return Semantics(role: SemanticsRole.form, child: form); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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:
| void placeForm() {} |
There was a problem hiding this comment.
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 !
| semanticsObject, | ||
| preferredLabelRepresentation: LabelRepresentation.ariaLabel, | ||
| ) { | ||
| setAriaRole('form'); |
There was a problem hiding this comment.
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:
| void placeForm() {} |
| semantics().semanticsEnabled = false; | ||
| } | ||
|
|
||
| void _testForms() { |
There was a problem hiding this comment.
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>''');There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated tests, thanks!
mdebbar
left a comment
There was a problem hiding this 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
engine/src/flutter/lib/web_ui/lib/src/engine/semantics/form.dart
Outdated
Show resolved
Hide resolved
engine/src/flutter/lib/web_ui/lib/src/engine/semantics/form.dart
Outdated
Show resolved
Hide resolved
chunhtai
left a comment
There was a problem hiding this 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>
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>
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>
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>
fix: #161628
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.