From 1daa17da597e6bf146d71a7ef319f7bb1341eef0 Mon Sep 17 00:00:00 2001 From: Rebecca Cremona Date: Thu, 7 Mar 2024 16:28:26 -0500 Subject: [PATCH 1/2] Give things a chance to render before trying to scroll into place. --- src/components/cap-case.js | 3 ++- src/components/cap-jurisdictions.js | 3 ++- src/templates/cap-about-page.js | 9 +++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/components/cap-case.js b/src/components/cap-case.js index 44a2db2..591d48f 100644 --- a/src/components/cap-case.js +++ b/src/components/cap-case.js @@ -384,11 +384,12 @@ export default class CapCase extends LitElement { this.handleHashChange(); } - handleHashChange() { + async handleHashChange() { const hash = window.location.hash.substring(1); // remove the '#' if (hash) { const element = this.shadowRoot.getElementById(hash); if (element) { + await new Promise(r => setTimeout(r, 100)); element.tabIndex = -1; element.scrollIntoView(); element.focus(); diff --git a/src/components/cap-jurisdictions.js b/src/components/cap-jurisdictions.js index 9f5a770..1219ad2 100644 --- a/src/components/cap-jurisdictions.js +++ b/src/components/cap-jurisdictions.js @@ -126,11 +126,12 @@ export default class CapJurisdictions extends LitElement { potentially problematic when we have to render case HTML, so I started using this pattern here. */ - handleHashChange() { + async handleHashChange() { const hash = window.location.hash.substring(1); // remove the '#' if (hash) { const element = this.shadowRoot.getElementById(hash); if (element) { + await new Promise(r => setTimeout(r, 100)); element.tabIndex = -1; element.scrollIntoView(); element.focus(); diff --git a/src/templates/cap-about-page.js b/src/templates/cap-about-page.js index eaeaa84..f5b2820 100644 --- a/src/templates/cap-about-page.js +++ b/src/templates/cap-about-page.js @@ -180,14 +180,15 @@ export class CapAboutPage extends LitElement { potentially problematic when we have to render case HTML, so I started using this pattern here. */ - handleHashChange() { + async handleHashChange() { const hash = window.location.hash.substring(1); // remove the '#' if (hash) { const element = this.shadowRoot.getElementById(hash); if (element) { - // wait a beat for things to draw. - window.requestAnimationFrame(() => {}); - window.requestAnimationFrame(() => element.scrollIntoView()); + await new Promise(r => setTimeout(r, 100)); + element.tabIndex = -1; + element.scrollIntoView(); + element.focus(); } } } From ce873019a5d95c03cafa8a216ad988226f394d89 Mon Sep 17 00:00:00 2001 From: Rebecca Cremona Date: Thu, 7 Mar 2024 16:32:49 -0500 Subject: [PATCH 2/2] Lint. --- src/components/cap-case.js | 2 +- src/components/cap-jurisdictions.js | 2 +- src/templates/cap-about-page.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/cap-case.js b/src/components/cap-case.js index 591d48f..1b29a0c 100644 --- a/src/components/cap-case.js +++ b/src/components/cap-case.js @@ -389,7 +389,7 @@ export default class CapCase extends LitElement { if (hash) { const element = this.shadowRoot.getElementById(hash); if (element) { - await new Promise(r => setTimeout(r, 100)); + await new Promise((r) => setTimeout(r, 100)); element.tabIndex = -1; element.scrollIntoView(); element.focus(); diff --git a/src/components/cap-jurisdictions.js b/src/components/cap-jurisdictions.js index 1219ad2..7119437 100644 --- a/src/components/cap-jurisdictions.js +++ b/src/components/cap-jurisdictions.js @@ -131,7 +131,7 @@ export default class CapJurisdictions extends LitElement { if (hash) { const element = this.shadowRoot.getElementById(hash); if (element) { - await new Promise(r => setTimeout(r, 100)); + await new Promise((r) => setTimeout(r, 100)); element.tabIndex = -1; element.scrollIntoView(); element.focus(); diff --git a/src/templates/cap-about-page.js b/src/templates/cap-about-page.js index f5b2820..88d8e18 100644 --- a/src/templates/cap-about-page.js +++ b/src/templates/cap-about-page.js @@ -185,7 +185,7 @@ export class CapAboutPage extends LitElement { if (hash) { const element = this.shadowRoot.getElementById(hash); if (element) { - await new Promise(r => setTimeout(r, 100)); + await new Promise((r) => setTimeout(r, 100)); element.tabIndex = -1; element.scrollIntoView(); element.focus();