@spectrum-web-components/base
Version:
The `SpectrumElement` base class as created by mixing `SpectrumMixin` onto `LitElement` adopts `dir` values from the `document` at connection time with a fallback to `lrt`. In a TypeScript context, it also enforces the presence of `this.shadowRoot` on ext
28 lines (27 loc) • 1 kB
JavaScript
;
export function conditionAttributeWithoutId(el, attribute, ids) {
const ariaDescribedby = el.getAttribute(attribute);
let descriptors = ariaDescribedby ? ariaDescribedby.split(/\s+/) : [];
descriptors = descriptors.filter(
(descriptor) => !ids.find((id) => descriptor === id)
);
if (descriptors.length) {
el.setAttribute(attribute, descriptors.join(" "));
} else {
el.removeAttribute(attribute);
}
}
export function conditionAttributeWithId(el, attribute, id) {
const ids = Array.isArray(id) ? id : [id];
const ariaDescribedby = el.getAttribute(attribute);
const descriptors = ariaDescribedby ? ariaDescribedby.split(/\s+/) : [];
const hadIds = ids.every((id2) => descriptors.indexOf(id2) > -1);
if (hadIds)
return () => {
return;
};
descriptors.push(...ids);
el.setAttribute(attribute, descriptors.join(" "));
return () => conditionAttributeWithoutId(el, attribute, ids);
}
//# sourceMappingURL=condition-attribute-with-id.dev.js.map