-
Notifications
You must be signed in to change notification settings - Fork 25
AutoScrollToElement Component
Richard Davis edited this page Aug 23, 2020
·
2 revisions
When visiting a link that includes a #fragment
, we need a mechanism to bring
that HTML element into focus.
<AutoScrollToElement />
watches for changes in store.router.location
and
scrolls to the top of the page when navigating to a new page. Then, scrolls to
the element identified by store.router.location.hash
, if present.
import React from 'react';
import { connect } from 'react-redux';
const AutoScrollToElement = ({ location, action }) => {
const { hash } = location;
React.useEffect(() => {
if (action !== 'PUSH') return; // only execute on PUSH action
window.scrollTo(0, 0);
const element = hash ? document.querySelector(hash) : null;
if (element) {
element.scrollIntoView();
window.scrollBy(0, -50); // compensate for header
}
}, [location]);
return null;
};
const mapStateToProps = ({ router: { location, action } }) => ({
location,
action
});
export default connect(mapStateToProps)(AutoScrollToElement);
Clicking the "Prior Activities Overview" link in the <Nav />
, takes you to
the /apd/previous-activites
page, and <AutoScrollToElement />
scrolls to the
element identified by the URL fragment (hash): #prev-activities-outline
.
- Team Working Agreement
- Team composition
- Workflows and processes
- Testing and bug filing
- Accessing eAPD
- Active Documentation:
- Sandbox Environment
- Glossary of acronyms
- APDs 101
- Design iterations archive
- MMIS Budget calculations
- HITECH Budget calculations
- Beyond the APD: From Paper to Pixels
- UX principles
- User research process
- Visual styling
- Content guide
- User research findings
- eAPD pilot findings
- User needs
- Developer info
- Development environment
- Coding Standards
- Development deployment
- Infrastructure Architecture
- Code Architecture
- Tech 101
- Authentication
- APD Auto Saving Process
- Resetting an Environment
- Hardware Software List
- Deploying Staging Production Instances Using Scripts
- Terraform 101 for eAPD
- Provisioning Infrastructure with Terraform
- WebSocket basics
- Operations-and-Support-Index
- Single Branch Deployment Strategy
- Ops and Support Overview
- Service Level AOI
- Incident Response Plan
- On-Call Policy
- Infrastructure Contingency Plan
- Updating CloudFront Security Headers
- Requesting and Installing TLS Certificates