-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Add a querySelectorAll helper function to use :scope when possible #3778
Changes from 1 commit
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 |
---|---|---|
|
@@ -374,6 +374,21 @@ export function childElementByTag(parent, tagName) { | |
} | ||
|
||
|
||
/** | ||
* A wrapper around native querySelectorAll to use :scope when possible. | ||
* @param {!Element} parent | ||
* @param {string} selector | ||
* @returns {!Array.<!Element>} | ||
*/ | ||
export function querySelectorAll(parent, selector) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Definitely would call this What is your concrete use case? Do you need a polyfill? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No not a polyfill, @dvoytenko suggested instead of making the call to the native querySelectorAll is to try to move it to a helper method that would use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renamed. |
||
if (scopeSelectorSupported) { | ||
const scopedSelectors = selector.split(',').map(sel => `:scope ${sel}`); | ||
return toArray(parent.querySelectorAll(scopedSelectors.join(','))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess I was trying to stick to the same return signature to other methods in |
||
} | ||
return toArray(parent.querySelectorAll(selector)); | ||
} | ||
|
||
|
||
/** | ||
* Returns element data-param- attributes as url parameters key-value pairs. | ||
* e.g. data-param-some-attr=value -> {someAttr: value}. | ||
|
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.
nit: no "period"
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.