Skip to content

Commit

Permalink
#530 Action list modal should be scrolled to bottom when opened
Browse files Browse the repository at this point in the history
  • Loading branch information
Adriána Kohanová committed Feb 1, 2021
1 parent bef6400 commit bcebc5e
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion js/components/tracking/trackingModal.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { memo, useCallback, useEffect } from 'react';
import React, { memo, useCallback, useEffect, useRef } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import Modal from '../common/Modal';
import { Grid, makeStyles, IconButton, Tooltip } from '@material-ui/core';
Expand Down Expand Up @@ -33,6 +33,7 @@ const useStyles = makeStyles(theme => ({
export const TrackingModal = memo(({ openModal, onModalClose }) => {
const classes = useStyles();
const dispatch = useDispatch();
const bottomRef = useRef();

const actionList = useSelector(state => state.trackingReducers.project_actions_list);
const orderedActionList = (actionList && actionList.sort((a, b) => a.timestamp - b.timestamp)) || [];
Expand All @@ -43,6 +44,16 @@ export const TrackingModal = memo(({ openModal, onModalClose }) => {
}
}, [dispatch, openModal]);

const scrollToBottom = () => {
if (bottomRef.current != null) {
bottomRef.current.scrollIntoView({
behavior: 'auto',
block: 'nearest',
inline: 'nearest'
});
}
};

useEffect(() => {
loadAllActions();
}, [loadAllActions]);
Expand Down Expand Up @@ -79,6 +90,12 @@ export const TrackingModal = memo(({ openModal, onModalClose }) => {
}
})}
</Timeline>
<div
ref={el => {
bottomRef.current = el;
scrollToBottom();
}}
></div>
</div>
</div>
</Grid>
Expand Down

0 comments on commit bcebc5e

Please sign in to comment.