LG-15252 Add accessible link to password strength feedback when creating password#11907
Conversation
app/javascript/packages/password-strength/password-strength-element.ts
Outdated
Show resolved
Hide resolved
app/javascript/packages/password-strength/password-strength-element.ts
Outdated
Show resolved
Hide resolved
aduth
left a comment
There was a problem hiding this comment.
Couple minor suggestions, but LGTM otherwise 👍
There was a problem hiding this comment.
Nice test coverage 👍 It could also be a good idea to incorporate what's expected to happen if the user clears a value after adding one (i.e. that the aria-describedby is removed again).
There was a problem hiding this comment.
I think this is a case where TypeScript is right in warning us that we can't guarantee that aria-describedby attribute is there. I might suggest using the optional chaining operator (?.) instead of the non-null assertion (!.).
| this.input.getAttribute('aria-describedby')!.replace(/\s*password-strength\s*/, ''), | |
| this.input.getAttribute('aria-describedby')?.replace(/\s*password-strength\s*/, ''), |
There was a problem hiding this comment.
This works if I add a non-null to the end otherwise TS was still complaining.
There was a problem hiding this comment.
This works if I add a non-null to the end otherwise TS was still complaining.
Can you share the error you are seeing?
There was a problem hiding this comment.
Ah, it's because the optional chaining will result in trying to set null as the value if there is no attribute present. Maybe we could address this by changing the else to an else if (this.input.hasAttribute('aria-describedby')), and then it'd be safe to use the non-null assertion.
There was a problem hiding this comment.
That TypeScript error remains but interestingly if I take the constant I'm setting in the if () { move it up and use it in both cases TypeScript stays happy. I think it's inferring string | null
There was a problem hiding this comment.
Yeah, that seems like a sensible approach 👍
I think the issue you were seeing is that TypeScript can't infer a connection between hasAttribute and getAttribute to know that the condition satisfied that the attribute definitely exists, whereas storing and reusing the variable reference, it knows it's safe to use if already checked in the condition.
There was a problem hiding this comment.
Thank you very much!
…assword strength feedback when focus on password field
…ribed-by attribute
7a1ed46 to
58b203a
Compare

🎫 Ticket
Link to the relevant ticket:
LG-15252
🛠 Summary of changes
In order to have screen reader recognize what shows up in the password strength block, we wrap the heading, 'rating' and hint text in a div and add its id to the password
aria-describedbyattribute.📜 Testing Plan
Confirm the changes.
Pre requisite: have ability for assistive screen reading on your device
👀 Screenshots
Screen recording of MacOS VoiceOver captioning showing rough idea of how a screen reader plays the described text
Screen.Recording.2025-02-20.at.2.20.30.PM.mov