Skip to content

Commit

Permalink
Merge pull request #91 from rebeccacremona/fix-anchor-links
Browse files Browse the repository at this point in the history
Fix in-page anchors; make consistent.
  • Loading branch information
rebeccacremona authored Mar 8, 2024
2 parents 021635d + ce87301 commit 8a10b44
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/components/cap-case.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,11 +392,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();
Expand Down
3 changes: 2 additions & 1 deletion src/components/cap-jurisdictions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
9 changes: 5 additions & 4 deletions src/templates/cap-about-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
Expand Down

0 comments on commit 8a10b44

Please sign in to comment.