@brightspace-ui/core 2.40.0 → 2.41.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/helpers/README.md CHANGED
@@ -107,6 +107,10 @@ isComposedAncestor(ancestorNode, node);
107
107
 
108
108
  // returns true/false whether the element is visible regardless of positioning
109
109
  isVisible(node);
110
+
111
+ // similar to document.querySelector or element.querySelector,
112
+ // except it queries not just the light DOM but also shadow DOM
113
+ querySelectorComposed(node, selector)
110
114
  ```
111
115
 
112
116
  ## Focus
package/helpers/dom.js CHANGED
@@ -227,3 +227,26 @@ export function isVisible(node) {
227
227
  return true;
228
228
 
229
229
  }
230
+
231
+ export function querySelectorComposed(node, selector) {
232
+
233
+ if (!node || (node.nodeType !== 1 && node.nodeType !== 9 && node.nodeType !== 11)) {
234
+ throw new TypeError('Invalid node. Must be nodeType document, element or document fragment');
235
+ }
236
+ if (typeof selector !== 'string') {
237
+ throw new TypeError('Invalid selector');
238
+ }
239
+
240
+ const elem = node.querySelector(selector);
241
+ if (elem) return elem;
242
+
243
+ const allElems = node.querySelectorAll('*');
244
+ for (const elem of allElems) {
245
+ if (elem.shadowRoot) {
246
+ const nestedElem = querySelectorComposed(elem.shadowRoot, selector);
247
+ if (nestedElem) return nestedElem;
248
+ }
249
+ }
250
+
251
+ return null;
252
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brightspace-ui/core",
3
- "version": "2.40.0",
3
+ "version": "2.41.0",
4
4
  "description": "A collection of accessible, free, open-source web components for building Brightspace applications",
5
5
  "type": "module",
6
6
  "repository": "https://github.com/BrightspaceUI/core.git",