|
@@ -17,6 +17,14 @@ function mapTags(tag) {
|
|
|
}
|
|
|
|
|
|
function extractTextForMagnify(e) {
|
|
|
+ const ariaLabel = e.path[0].getAttribute('aria-label')
|
|
|
+ if (e.path[0].getAttribute('aria-label')) {
|
|
|
+ return {
|
|
|
+ elemDisc: '',
|
|
|
+ elemContent: ariaLabel
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// console.log(e)
|
|
|
if (e.path[0].nodeName === 'HTML') {
|
|
|
return
|
|
@@ -65,7 +73,7 @@ function isSameObject(object1, object2) {
|
|
|
return true
|
|
|
}
|
|
|
|
|
|
-function getAndFocusNextNodeWithClassName(className) {
|
|
|
+function getAndFocusNextNodeWithCustomAttribute(attriName) {
|
|
|
const startNode = (document.activeElement || document.body)
|
|
|
|
|
|
const treeWalker = document.createTreeWalker(document.body, NodeFilter.SHOW_ELEMENT)
|
|
@@ -80,14 +88,14 @@ function getAndFocusNextNodeWithClassName(className) {
|
|
|
console.log('往下没找到')
|
|
|
break
|
|
|
}
|
|
|
- if (nextNode.classList && [...nextNode.classList].some(item => item === className)) {
|
|
|
+ if (nextNode.dataset[attriName] !== undefined) {
|
|
|
console.log('往下找到了')
|
|
|
targetNode = nextNode
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (!targetNode && startNode !== document.body) {
|
|
|
+ if (!targetNode && (startNode !== document.body)) {
|
|
|
treeWalker.currentNode = document.body
|
|
|
// eslint-disable-next-line
|
|
|
while(true) {
|
|
@@ -96,8 +104,8 @@ function getAndFocusNextNodeWithClassName(className) {
|
|
|
console.log('往上也没找到')
|
|
|
break
|
|
|
}
|
|
|
- if (nextNode.classList && [...nextNode.classList].some(item => item === className)) {
|
|
|
- console.log('网上找到了')
|
|
|
+ if (nextNode.dataset[attriName] !== undefined) {
|
|
|
+ console.log('往上找到了')
|
|
|
targetNode = nextNode
|
|
|
break
|
|
|
}
|
|
@@ -106,6 +114,10 @@ function getAndFocusNextNodeWithClassName(className) {
|
|
|
|
|
|
if (targetNode) {
|
|
|
targetNode.focus()
|
|
|
+ if (document.activeElement !== targetNode) {
|
|
|
+ targetNode.setAttribute('tabindex', '0')
|
|
|
+ targetNode.focus()
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return targetNode
|
|
@@ -197,5 +209,5 @@ export default {
|
|
|
isSameObject,
|
|
|
iterateOnFocusableNode,
|
|
|
debounce,
|
|
|
- getAndFocusNextNodeWithClassName,
|
|
|
+ getAndFocusNextNodeWithCustomAttribute,
|
|
|
}
|