-
-
Notifications
You must be signed in to change notification settings - Fork 382
feat(Utility): add all parameter on getDescribedElement method #7778
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,4 @@ | ||||||||||||||||
| import EventHandler from "./event-handler.js" | ||||||||||||||||
| import EventHandler from "./event-handler.js" | ||||||||||||||||
|
|
||||||||||||||||
| const vibrate = () => { | ||||||||||||||||
| if ('vibrate' in window.navigator) { | ||||||||||||||||
|
|
@@ -420,14 +420,14 @@ const drag = (element, start, move, end) => { | |||||||||||||||
| element.addEventListener('touchstart', handleDragStart) | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| const getDescribedElement = (element, selector = 'aria-describedby') => { | ||||||||||||||||
| const getDescribedElement = (element, selector = 'aria-describedby', all = false) => { | ||||||||||||||||
| if (isElement(element)) { | ||||||||||||||||
| let id = element.getAttribute(selector) | ||||||||||||||||
| if (id) { | ||||||||||||||||
| if (id.indexOf('.') === -1) { | ||||||||||||||||
| id = `#${id}` | ||||||||||||||||
| } | ||||||||||||||||
| return document.querySelector(id) | ||||||||||||||||
| return all ? document.querySelectorAll(id) : document.querySelector(id) | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
|
||||||||||||||||
| } | |
| } | |
| if (all) { | |
| // Always return a NodeList for the "all" mode, even when there is no match, | |
| // to mirror querySelectorAll semantics and keep the return type consistent. | |
| return document.querySelectorAll('[data-utility-empty-aria-describedby=""]') | |
| } |
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.
issue: Handling multiple aria-describedby IDs with
allis likely incorrect with the current selector construction.With
all = true, this now doesquerySelectorAll(id), butaria-describedbyoften holds a space-separated list of IDs (e.g."id1 id2"). That makesidbecome"#id1 id2", which is parsed as a descendant selector, not multiple IDs, so it won’t reliably return all referenced elements. Ifallis meant to return all described elements, you likely need to split on whitespace, prefix each with#, and either build a comma-separated selector forquerySelectorAllor usegetElementByIdper ID and aggregate the results.