Skip to content
This repository was archived by the owner on Aug 8, 2024. It is now read-only.

Commit

Permalink
refactor: handleNavigateTop
Browse files Browse the repository at this point in the history
  • Loading branch information
LiKang6688 committed Jun 14, 2022
1 parent 38abf12 commit f012fb7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/table/components/TableWrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,8 @@ export default function TableWrapper(props) {
const memoedContainer = tableBodyWrapperRef.current;
if (!memoedContainer) return () => {};

const keyDownHandler = (evt) => {
const keyDownHandler = (evt) =>
evt.key === 'ArrowUp' && handleNavigateTop({ tableContainerRef, focusedCellCoord, rootElement });
};
memoedContainer.addEventListener('keydown', keyDownHandler);

return () => {
Expand Down
4 changes: 2 additions & 2 deletions src/table/utils/handle-scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const handleHorizontalScroll = (evt, isRTL, memoedContainer) => {
};

export const handleNavigateTop = ({ tableContainerRef, focusedCellCoord, rootElement }) => {
if (!tableContainerRef.current?.scrollTo || !rootElement) return;
if (!tableContainerRef.current.scrollTo) return;

const [x, y] = focusedCellCoord;
const tableHead = rootElement.getElementsByClassName('sn-table-head-cell')[0];
Expand All @@ -37,7 +37,7 @@ export const handleNavigateTop = ({ tableContainerRef, focusedCellCoord, rootEle
const targetOffsetTop = tableContainerRef.current.scrollTop - cell.offsetHeight - tableHead.offsetHeight;
tableContainerRef.current.scrollTo({
top: Math.max(0, targetOffsetTop),
behavior: 'smooth',
behavior: 'instant',
});
}
};

0 comments on commit f012fb7

Please sign in to comment.