-
Notifications
You must be signed in to change notification settings - Fork 55
[Accessibility] Adds support for an accessible "clear" button #53
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
Conversation
8e7d52a to
f1c14f9
Compare
454caed to
a59d75d
Compare
| feedback: HTMLElement | null | ||
| autoselectEnabled: boolean | ||
| clientOptions: NodeListOf<HTMLElement> | null | ||
| clearButton: HTMLElement | 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.
we can be more strict and use HTMLButtonElement
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.
Technically, someone can add the ID to another element like an anchor or a span. 🤔 I would like to keep it this way just in case, but I'm open to other ideas.
|
Could we please provide some detail as to what the current limitations are for |
Co-authored-by: Manuel Puyol <[email protected]>
Co-authored-by: Manuel Puyol <[email protected]>
…to-complete-element into feature/a11y-clearable
While
In Chrome, for example, this @keithamus Do you think restricting this input not to use |
Thank you for expanding on this.
Yes please. |
|
I had a great conversation with @manuelpuyol today about the button-replacement idea and will be updating the implementation to do a more traditional error / prevent rendering instead. Updates coming as soon as I have time :) |
…ifferent error handling of clear button
src/autocomplete.ts
Outdated
| // if clearButton is not a button, show error | ||
| if (this.clearButton && this.clearButton.tagName.toLowerCase() !== 'button') { | ||
| const buttonErrorMessage = `Accessibility violation: ${this.clearButton.tagName} provided for clear button. Please use a "button" element.` | ||
| const buttonErrorText = '\u26a0 Error: See console' | ||
| const buttonError = document.createElement('span') | ||
| buttonError.setAttribute('style', 'color:#92140C') | ||
| buttonError.textContent = buttonErrorText | ||
| this.clearButton.parentNode?.replaceChild(buttonError, this.clearButton) | ||
| this.clearButton = buttonError | ||
| throw new Error(buttonErrorMessage) | ||
| } | ||
|
|
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.
We do not want to be presenting errors to (potentially) the user. I don't think this should be here.
Instead of reporting accessibility violations within the main code here, we might want to add an additional file which can provide custom rules to Axe. Something like axe.ts with the following:
export default [
{
id: 'auto-complete-element-clear-button-is-button',
impact: 'critical',
selector: 'auto-complete-element [id$="clear"]:not(button)',
excludeHidden: false,
metadata: {
description: "Auto-Complete clear elements must be a "button" element",
helpUrl: "https://github.com/github/auto-complete-element"
}
}
]We can then load this into the existing devtools we have for GitHub (which includes axe-core) and it can report on these types of violations during development without impacting the user.
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.
Let's set up a sync to chat about options for this. I don't want end-users to see errors either, but this package doesn't include Axe, so I'd like to avoid relying on it. It is open source and could be used anywhere. I'll DM you.
Co-authored-by: Keith Cirkel <[email protected]>
Co-authored-by: Keith Cirkel <[email protected]>
|
@manuelpuyol @keithamus This PR will remove the controversial error handling methods, and those will be tackled in a future PR. Preview approach will be:
|
…to-complete-element into feature/a11y-clearable
keithamus
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
Summary
New features
If an element with
<input-id>-clearis detected in the autocomplete, clicking that button will:Demo
Screen.Recording.2021-11-12.at.9.56.57.AM.mov
^ The above recording shows the user focusing on the input, typing "bo", selecting the "X" clear button, and their focus being moved back to the input. The screenreader announcement is visible and reads "Input cleared. Suggestions hidden."
cc @github/accessibility