diff --git a/demo/src/app/docs/demo-section-components/demo-examples-section/examples.component.ts b/demo/src/app/docs/demo-section-components/demo-examples-section/examples.component.ts index 30365f19ae..e425c98a0d 100644 --- a/demo/src/app/docs/demo-section-components/demo-examples-section/examples.component.ts +++ b/demo/src/app/docs/demo-section-components/demo-examples-section/examples.component.ts @@ -16,9 +16,25 @@ export class ExamplesComponent { } @HostListener('document:click', ['$event']) - preventEmptyHrefNav(event: Event) { - if (event && event.target && (event.target as Element).getAttribute('href') === '#') { + preventEmptyHrefNav(event: MouseEvent & {target: Element}): void { + let element: Element = event.target; + let preventNav = element.getAttribute('href') === '#'; + + if (preventNav) { event.preventDefault(); + return; + } + + if (element.tagName !== 'A') { + while (element !== document.body) { + if (preventNav) { + event.preventDefault(); + return; + } + element = element.parentElement; + preventNav = element.getAttribute('href') === '#'; + } } } } +