From e075e23b91098e73bf9ab9ed1ff9db991c7de252 Mon Sep 17 00:00:00 2001 From: Martin Dragnev <37667452+mddragnev@users.noreply.github.com> Date: Thu, 26 Oct 2023 18:59:58 +0300 Subject: [PATCH] Add a way to prevent scroll in the samples browser (#573) Co-authored-by: HUSSAR-mtrela (Martin Trela) --- browser/src/router.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/browser/src/router.ts b/browser/src/router.ts index e3f3d8fbbf..37331fa52d 100644 --- a/browser/src/router.ts +++ b/browser/src/router.ts @@ -58,6 +58,7 @@ export class Router { private displaySample(sample: any) { let tagName = sample.htmlTagName; this._targetEle.innerHTML = `<${tagName} class="sample-content">`; + this._targetEle.addEventListener('wheel', this.preventDocumentScroll, { passive: false }); } private public_url = ""; @@ -65,6 +66,9 @@ export class Router { public async navigateToRoute(route: string) { let navBarIsHidden: boolean = true; + // clear event listener before routing to a new sample + this._targetEle.removeEventListener('wheel', this.preventDocumentScroll); + if (route.indexOf("/webcomponents-demos") === 0) { this.public_url = "/webcomponents-demos"; route = route.substring("/webcomponents-demos".length); @@ -162,4 +166,10 @@ export class Router { // } } + private preventDocumentScroll(event:any) { + if (event.target.outerHTML.toLowerCase().includes('igx')) { + event.preventDefault(); + } + } + }