Skip to content

Commit

Permalink
Merge branch 'release/v1.47.0' into fix/image-aspect-ratio
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored May 17, 2023
2 parents e64736c + 81a2fd2 commit 5c13a6f
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ class DDSTableOfContents extends HostListenerMixin(
*/
private _tagNamesToAvoid = [`${ddsPrefix}-video-player`];

/**
* The name of an attribute that will prevent the DOM element and any elements
* in its subtree from being added to the ToC.
*/
private _disableTargetAttribute = 'no-toc';

/**
* Boolean checking if page is RTL
*/
Expand Down Expand Up @@ -363,7 +369,10 @@ class DDSTableOfContents extends HostListenerMixin(
* Sets targets used for generating the table of contents.
*/
private _setTargets(nodes: Node[]) {
const { _tagNamesToAvoid: tagNamesToAvoid } = this;
const {
_tagNamesToAvoid: tagNamesToAvoid,
_disableTargetAttribute: disableTargetAttribute,
} = this;
const { selectorTarget } = this.constructor as typeof DDSTableOfContents;
this._targets = nodes.reduce((acc, node) => {
if (node instanceof HTMLElement) {
Expand All @@ -376,9 +385,9 @@ class DDSTableOfContents extends HostListenerMixin(
elem.innerText.match(notWhiteSpace) ||
elem.dataset.title?.match(notWhiteSpace);
const hasNameAttr = elem.matches(selectorTarget);
const notExcluded = !tagNamesToAvoid.includes(
elem.tagName.toLowerCase()
);
const notExcluded =
!tagNamesToAvoid.includes(elem.tagName.toLowerCase()) &&
!elem.closest(`[${disableTargetAttribute}]`);

return hasTitle && hasNameAttr && notExcluded;
});
Expand Down

0 comments on commit 5c13a6f

Please sign in to comment.