aria-hidden
Advanced tools
Comparing version 1.2.1 to 1.2.2
@@ -12,2 +12,18 @@ var getDefaultParent = function (originalTarget) { | ||
var lockCount = 0; | ||
var unwrapHost = function (node) { | ||
return node && (node.host || unwrapHost(node.parentNode)); | ||
}; | ||
var correctTargets = function (parent, targets) { | ||
return targets.map(function (target) { | ||
if (parent.contains(target)) { | ||
return target; | ||
} | ||
var correctedTarget = unwrapHost(target); | ||
if (correctedTarget && parent.contains(correctedTarget)) { | ||
return correctedTarget; | ||
} | ||
console.error('aria-hidden', target, 'in not contained inside', parent, '. Doing nothing'); | ||
return null; | ||
}).filter(function (x) { return Boolean(x); }); | ||
}; | ||
/** | ||
@@ -22,3 +38,3 @@ * Marks everything except given node(or nodes) as aria-hidden | ||
var applyAttributeToOthers = function (originalTarget, parentNode, markerName, controlAttribute) { | ||
var targets = Array.isArray(originalTarget) ? originalTarget : [originalTarget]; | ||
var targets = correctTargets(parentNode, Array.isArray(originalTarget) ? originalTarget : [originalTarget]); | ||
if (!markerMap[markerName]) { | ||
@@ -25,0 +41,0 @@ markerMap[markerName] = new WeakMap(); |
@@ -12,2 +12,14 @@ const getDefaultParent = (originalTarget) => { | ||
let lockCount = 0; | ||
const unwrapHost = (node) => node && (node.host || unwrapHost(node.parentNode)); | ||
const correctTargets = (parent, targets) => targets.map(target => { | ||
if (parent.contains(target)) { | ||
return target; | ||
} | ||
const correctedTarget = unwrapHost(target); | ||
if (correctedTarget && parent.contains(correctedTarget)) { | ||
return correctedTarget; | ||
} | ||
console.error('aria-hidden', target, 'in not contained inside', parent, '. Doing nothing'); | ||
return null; | ||
}).filter((x) => Boolean(x)); | ||
/** | ||
@@ -22,3 +34,3 @@ * Marks everything except given node(or nodes) as aria-hidden | ||
const applyAttributeToOthers = (originalTarget, parentNode, markerName, controlAttribute) => { | ||
const targets = Array.isArray(originalTarget) ? originalTarget : [originalTarget]; | ||
const targets = correctTargets(parentNode, Array.isArray(originalTarget) ? originalTarget : [originalTarget]); | ||
if (!markerMap[markerName]) { | ||
@@ -25,0 +37,0 @@ markerMap[markerName] = new WeakMap(); |
@@ -15,2 +15,18 @@ "use strict"; | ||
var lockCount = 0; | ||
var unwrapHost = function (node) { | ||
return node && (node.host || unwrapHost(node.parentNode)); | ||
}; | ||
var correctTargets = function (parent, targets) { | ||
return targets.map(function (target) { | ||
if (parent.contains(target)) { | ||
return target; | ||
} | ||
var correctedTarget = unwrapHost(target); | ||
if (correctedTarget && parent.contains(correctedTarget)) { | ||
return correctedTarget; | ||
} | ||
console.error('aria-hidden', target, 'in not contained inside', parent, '. Doing nothing'); | ||
return null; | ||
}).filter(function (x) { return Boolean(x); }); | ||
}; | ||
/** | ||
@@ -25,3 +41,3 @@ * Marks everything except given node(or nodes) as aria-hidden | ||
var applyAttributeToOthers = function (originalTarget, parentNode, markerName, controlAttribute) { | ||
var targets = Array.isArray(originalTarget) ? originalTarget : [originalTarget]; | ||
var targets = correctTargets(parentNode, Array.isArray(originalTarget) ? originalTarget : [originalTarget]); | ||
if (!markerMap[markerName]) { | ||
@@ -28,0 +44,0 @@ markerMap[markerName] = new WeakMap(); |
{ | ||
"name": "aria-hidden", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "Cast aria-hidden to everything, except...", | ||
@@ -5,0 +5,0 @@ "main": "dist/es5/index.js", |
@@ -62,2 +62,23 @@ # aria-hidden | ||
⚠️ Note - inert **will disable any interactions** with _suppressed_ elements ⚠️ | ||
### Suppressing interactivity without inert | ||
One can `marker`, the third argument to a function, to mark hidden elements. | ||
Later one can create a style matching given marker to apply `pointer-events:none` | ||
```css | ||
[hidden-node] { | ||
pointer-events: none; | ||
} | ||
``` | ||
```tsx | ||
hideOthers(notThisOne, undefined /*parent = document*/, 'hidden-node'); | ||
``` | ||
Generally speaking the same can be archived by addressing `[aria-hidden]` nodes, but | ||
not all `aria-hidden` nodes are expected to be non-interactive. | ||
Hence, it's better to separate concerns. | ||
# Inspiration | ||
@@ -64,0 +85,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30160
560
100