Skip to content

Commit 30b2e77

Browse files
committed
#4502 scroll to anchor on load
1 parent fd7d5cb commit 30b2e77

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/shared/components/PolicyPages/index.jsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
* PolicyPages component.
33
*/
44
import _ from 'lodash';
5-
import React, { useState } from 'react';
5+
import React, { useState, useEffect } from 'react';
66
import PT from 'prop-types';
77
import Sticky from 'react-stickynode';
8-
import { config, Link } from 'topcoder-react-utils';
8+
import { config, Link, isomorphy } from 'topcoder-react-utils';
99
import cn from 'classnames';
1010
import ContentBlock from 'components/Contentful/ContentBlock';
1111
import Error404 from 'components/Error404';
@@ -29,6 +29,18 @@ function PolicyPages({
2929
policies: this === 'policies', legal: this === 'legal',
3030
});
3131
}
32+
// auto scroll to anchors
33+
useEffect(() => {
34+
if (isomorphy.isClientSide()) {
35+
const { hash } = window.location;
36+
setTimeout(() => {
37+
const anchor = document.getElementById(hash ? hash.slice(1) : null);
38+
if (anchor) {
39+
anchor.scrollIntoView({ behavior: 'smooth', block: 'start', inline: 'nearest' });
40+
}
41+
}, 5000);
42+
}
43+
});
3244

3345
let { slug } = match.params;
3446
const pages = policyData.Policies.concat(policyData.Legal);
@@ -94,10 +106,6 @@ function PolicyPages({
94106
);
95107
}
96108

97-
PolicyPages.defaultProps = {
98-
99-
};
100-
101109
PolicyPages.propTypes = {
102110
match: PT.shape().isRequired,
103111
policyData: PT.shape().isRequired,

src/shared/components/PolicyPages/styles.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
font-weight: 600;
8888
padding: 15px;
8989
border-bottom: 1px solid #e0e0e0;
90+
outline: none;
9091

9192
&::before {
9293
display: inline-block;

0 commit comments

Comments
 (0)