Merge pull request #15154 from Snuffleupagus/xfa-rm-id

Replace element `id`s with custom attributes in the xfaLayer
This commit is contained in:
Jonas Jenwald 2022-07-10 16:06:17 +02:00 committed by GitHub
commit 0205597bd0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -107,28 +107,34 @@ class XfaLayer {
attributes.name = `${attributes.name}-${intent}`; attributes.name = `${attributes.name}-${intent}`;
} }
for (const [key, value] of Object.entries(attributes)) { for (const [key, value] of Object.entries(attributes)) {
// We don't need to add dataId in the html object but it can if (value === null || value === undefined) {
// be useful to know its value when writing printing tests:
// in this case, don't skip dataId to have its value.
if (value === null || value === undefined || key === "dataId") {
continue; continue;
} }
if (key !== "style") { switch (key) {
if (key === "textContent") { case "class":
html.textContent = value;
} else if (key === "class") {
if (value.length) { if (value.length) {
html.setAttribute(key, value.join(" ")); html.setAttribute(key, value.join(" "));
} }
} else { break;
if (isHTMLAnchorElement && (key === "href" || key === "newWindow")) { case "dataId":
continue; // Handled below. // We don't need to add dataId in the html object but it can
// be useful to know its value when writing printing tests:
// in this case, don't skip dataId to have its value.
break;
case "id":
html.setAttribute("data-element-id", value);
break;
case "style":
Object.assign(html.style, value);
break;
case "textContent":
html.textContent = value;
break;
default:
if (!isHTMLAnchorElement || (key !== "href" && key !== "newWindow")) {
html.setAttribute(key, value);
} }
html.setAttribute(key, value);
}
} else {
Object.assign(html.style, value);
} }
} }
@ -140,8 +146,7 @@ class XfaLayer {
); );
} }
// Set the value after the others to be sure overwrite // Set the value after the others to be sure to overwrite any other values.
// any other values.
if (storage && attributes.dataId) { if (storage && attributes.dataId) {
this.setupStorage(html, attributes.dataId, element, storage); this.setupStorage(html, attributes.dataId, element, storage);
} }