Skip to content

Commit 676409d

Browse files
Merge branch 'main' into feat-element-role-mapping-updates
2 parents ad0a874 + f5b8f4c commit 676409d

File tree

4 files changed

+51
-44
lines changed

4 files changed

+51
-44
lines changed

flow/dequal.js

-3
This file was deleted.

package-lock.json

-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,5 @@
6666
"not dead",
6767
"not op_mini all",
6868
"ie 11"
69-
],
70-
"dependencies": {
71-
"dequal": "^2.0.3"
72-
}
69+
]
7370
}

src/elementRoleMap.js

+50-21
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* @flow
33
*/
44

5-
import { dequal } from 'dequal/lite';
65
import iterationDecorator from "./util/iterationDecorator";
76
import rolesMap from './rolesMap';
87

@@ -24,25 +23,7 @@ for (let i = 0; i < keys.length; i++) {
2423
if (relation.module === 'HTML') {
2524
const concept = relation.concept;
2625
if (concept) {
27-
const elementRoleRelation: ?ElementARIARoleRelationTuple = elementRoles.find(relation => dequal(relation, concept));
28-
let roles: RoleSet;
29-
30-
if (elementRoleRelation) {
31-
roles = elementRoleRelation[1];
32-
} else {
33-
roles = [];
34-
}
35-
let isUnique = true;
36-
for (let i = 0; i < roles.length; i++) {
37-
if (roles[i] === key) {
38-
isUnique = false;
39-
break;
40-
}
41-
}
42-
if (isUnique) {
43-
roles.push(key);
44-
}
45-
elementRoles.push([concept, roles]);
26+
elementRoles.push([concept, [key]]);
4627
}
4728
}
4829
}
@@ -67,7 +48,7 @@ const elementRoleMap: TAriaQueryMap<
6748
},
6849
get: function (key: ARIARoleRelationConcept): ?RoleSet {
6950
const item = elementRoles.find(tuple => (
70-
key.name === tuple[0].name && dequal(key.attributes, tuple[0].attributes)
51+
key.name === tuple[0].name && ariaRoleRelationConceptAttributeEquals(key.attributes, tuple[0].attributes)
7152
));
7253
return item && item[1];
7354
},
@@ -82,6 +63,54 @@ const elementRoleMap: TAriaQueryMap<
8263
},
8364
};
8465

66+
function ariaRoleRelationConceptAttributeEquals(
67+
a?: Array<ARIARoleRelationConceptAttribute>,
68+
b?: Array<ARIARoleRelationConceptAttribute>,
69+
): boolean {
70+
71+
if (a === undefined && b !== undefined) {
72+
return false;
73+
}
74+
75+
if (a !== undefined && b === undefined) {
76+
return false;
77+
}
78+
79+
if (a !== undefined && b !== undefined) {
80+
if (a.length !== b.length) {
81+
return false;
82+
}
83+
84+
for (let i = 0; i < a.length; i++) {
85+
if (a[i].name !== b[i].name || a[i].value !== b[i].value) {
86+
return false;
87+
}
88+
89+
if (a[i].constraints === undefined && b[i].constraints !== undefined) {
90+
return false;
91+
}
92+
93+
if (a[i].constraints !== undefined && b[i].constraints === undefined) {
94+
return false
95+
}
96+
97+
if (a[i].constraints !== undefined && b[i].constraints !== undefined) {
98+
if (a[i].constraints.length !== b[i].constraints.length) {
99+
return false;
100+
}
101+
102+
for (let j = 0; j < a[i].constraints.length; j++) {
103+
if (a[i].constraints[j] !== b[i].constraints[j]) {
104+
return false;
105+
}
106+
}
107+
}
108+
}
109+
}
110+
111+
return true;
112+
}
113+
85114
export default (
86115
iterationDecorator(
87116
elementRoleMap,

0 commit comments

Comments
 (0)