-
Notifications
You must be signed in to change notification settings - Fork 6.8k
fix(input): placeholder being read out twice by some screen readers #10466
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
fix(input): placeholder being read out twice by some screen readers #10466
Conversation
src/lib/input/input.ts
Outdated
@@ -299,6 +300,14 @@ export class MatInput extends _MatInputMixinBase implements MatFormFieldControl< | |||
// FormsModule or ReactiveFormsModule, because Angular forms also listens to input events. | |||
} | |||
|
|||
/** Determines the value of the native `placeholder` attribute that should be used in the DOM. */ | |||
_getNativePlaceholderValue() { |
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.
Add a note that we can get rid of this once we remove the legacy form-field style, since its the only style the supports promoting the placeholder to a label
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.
Done.
4cd2c80
to
a7cd75a
Compare
a7cd75a
to
522e174
Compare
824f3c5
to
7e8eaa0
Compare
2eef585
to
ebd9210
Compare
ebd9210
to
0a2b75b
Compare
needs rebase |
0a2b75b
to
c9bfb11
Compare
src/material/input/input.ts
Outdated
// TODO: can be removed once we get rid of the `legacy` style for the form field, because it's | ||
// the only one that supports promoting the placeholder to a label. | ||
const formField = this._formField; | ||
return (!formField || !formField._hideControlPlaceholder()) ? this.placeholder : 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.
Small issue found in testing that needs to be resolved before we can merge.
This function calls the form field's _hideControlPlaceholder()
, which checks the control's _shouldLabelFloat
. In the case where the control is MatChipList
, that property is a getter:
get shouldLabelFloat(): boolean { return !this.empty || this.focused; }
It checks the empty
property of the MatChipList
, which is also a getter:
get empty(): boolean {
return (!this._chipInput || this._chipInput.empty) && this.chips.length === 0;
}
Here we find that this.chips.length
throws an exception because this.chips
is undefined
since the content of the list has not yet been initialized.
Here's a reproduction of the issue we are seeing: https://stackblitz.com/edit/components-issue-2obaho?file=app%2Fapp.component.ts
It's using the same hook timing of the placeholder host binding, and you can see in the debug console that an exception is thrown when calling _hideControlPlaceholder()
c9bfb11
to
7d7a7ae
Compare
Thank you for looking into it @andrewseguin. I've added an extra null check for the chips and fixed the compilation errors. |
Looks like there seems to be a size change causing the test to fail |
c4dca9d
to
1538051
Compare
Fixed. |
Looks like another size error came up |
There are roughly 100-200 tests internally that fail due to selectors like If that attribute is added ahead of this PR, then the tests could be migrated away from using the Ideally those tests use harnesses, but it will likely be a very long time until all those tests are migrated. |
cfd81c3
to
11d40a6
Compare
This is a prerequisite to make landing angular#10466 easier in g3. Mirrors the native placeholder value in a data attribute so that we can read it even when it has been removed.
This is a prerequisite to make landing #10466 easier in g3. Mirrors the native placeholder value in a data attribute so that we can read it even when it has been removed.
We're seeing some cases of |
11d40a6
to
b258683
Compare
Thank you for the repro @andrewseguin, I've updated the PR to work around the test failure. |
This is a prerequisite to make landing #10466 easier in g3. Mirrors the native placeholder value in a data attribute so that we can read it even when it has been removed.
This is a prerequisite to make landing #10466 easier in g3. Mirrors the native placeholder value in a data attribute so that we can read it even when it has been removed.
Needs rebase |
Currently we hide the native placeholder using CSS while we mirror its value in the form field label, however because the value is still in the DOM, some screen readers will read it out twice: once for the label and once for the attribute. These changes remove the attribute from the DOM if it isn't supposed to be shown. Fixes angular#9721.
Rebased. |
b258683
to
d1a64c3
Compare
…ngular#10466) Currently we hide the native placeholder using CSS while we mirror its value in the form field label, however because the value is still in the DOM, some screen readers will read it out twice: once for the label and once for the attribute. These changes remove the attribute from the DOM if it isn't supposed to be shown. Fixes angular#9721.
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Currently we hide the native placeholder using CSS while we mirror its value in the form field label, however because the value is still in the DOM, some screen readers will read it out twice: once for the label and once for the attribute. These changes remove the attribute from the DOM if it isn't supposed to be shown.
Fixes #9721.