forked from androidx/androidx
-
Notifications
You must be signed in to change notification settings - Fork 118
Fix TextField accessibility - contentDescription was ignored #2680
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
kdroidFilter
wants to merge
3
commits into
JetBrains:jb-main
Choose a base branch
from
kdroidFilter:textfield-accessible-name
base: jb-main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is there a reason we should not just always return
?
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.e., why only if
setText != null?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.
The
setText != nullcheck is necessary becauseText ?: ContentDescriptiondoesn't work for the fallback case.I tested your suggestion and it fails the
textFieldAccessibleNameFallsBackToTextContenttest. The issue is that for TextFields, SemanticsProperties.Text may exist in the config but doesn't provide the actual text content—that comes from the text field (via AccessibleText).So when there's no
contentDescription, we needtext?.toString()as fallback, notSemanticsProperties.Text.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.
Err, sorry, I meant the other way around (
ContentDescription ?: Text).My point was that it seems to me the content description should be used (if set) not just for text fields (or editable text components in general).
Uh oh!
There was an error while loading. Please reload this page.
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 understand your point—using
ContentDescription ?: Textfor all components would be more consistent.However, this fails the
textFieldAccessibleNameFallsBackToTextContenttest because SemanticsProperties.Text is null/empty for editable TextFields.The fallback needs
text?.toString()(from the Java AccessibleText API), not SemanticsProperties.Text (from Compose semantics). The setText != null check ensures we use the correct fallback source specifically for text fields.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.
My question wasn't about
semanticsConfig.getOrNull(SemanticsProperties.Text)vs.text(which is just a calculated property ofComposeAccessibleComponent, by the way; it doesn't come from the Java API), although that's a valid question too. It was about usingContentDescriptioneven ifsetTextisnull. Is there a reason not to do that?About the question of
semanticsConfig.getOrNull(SemanticsProperties.Text)vs.text(which itself isEditableText ?: Text): I don't think it's correct to useEditableTextingetAccessibleName(orgetAccessibleDescription.So my suggestion is:
getAccessibleNamereturnContentDescription ?: Text.getAccessibleDescriptionreturnContentDescription.Do you know of any cases where this would result in undesirable behavior from the OS accessibility system?
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.
Hmm,
getAccessibleDescriptionalready returnsContentDescription.So just the first suggestion then.
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.
Ah, sorry, I hadn’t understood it properly.
On my side, I also didn’t fully understand why
EditableTextwas being used ingetAccessibleName, but I intentionally kept it to avoid introducing overly large changes. My goal was really to fix this specific bug, without further altering the existing behavior.To my knowledge, this should not cause any issues with screen readers: they should be able to read the content correctly through the
AccessibleTextinterface.Would you like me to apply the proposed changes?
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.
Yes, let's do that, and if/when anyone complains we'll fix it (and document exactly why).
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've implemented your suggestion.
However, when running all AccessibilityTest tests together, 10 tests fail with
assert(activeControllers.isEmpty())in the cleanup. These same tests pass when run individually.