Skip to content

Commit

Permalink
Scroll to currently softfocus cell (#1008)
Browse files Browse the repository at this point in the history
* - scroll to currently softfocus cell

* - moved useEffect to CellSoftFocus component
  • Loading branch information
brendanlaschke authored Jul 31, 2023
1 parent f111440 commit 700b567
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Ref } from 'react';
import styled from '@emotion/styled';

type Props = {
softFocus?: boolean;
onClick?: () => void;
scrollRef?: Ref<HTMLDivElement>;
};

export const EditableCellDisplayModeOuterContainer = styled.div<
Expand Down Expand Up @@ -37,6 +39,7 @@ export function EditableCellDisplayContainer({
children,
softFocus,
onClick,
scrollRef,
}: React.PropsWithChildren<Props>) {
return (
<EditableCellDisplayModeOuterContainer
Expand All @@ -47,6 +50,7 @@ export function EditableCellDisplayContainer({
}
onClick={onClick}
softFocus={softFocus}
ref={scrollRef}
>
<EditableCellDisplayModeInnerContainer>
{children}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PropsWithChildren } from 'react';
import { PropsWithChildren, useEffect, useRef } from 'react';

import { useScopedHotkeys } from '@/ui/utilities/hotkey/hooks/useScopedHotkeys';
import { isNonTextWritingKey } from '@/ui/utilities/hotkey/utils/isNonTextWritingKey';
Expand All @@ -13,6 +13,12 @@ type OwnProps = PropsWithChildren<unknown>;
export function EditableCellSoftFocusMode({ children }: OwnProps) {
const { openEditableCell } = useEditableCell();

const scrollRef = useRef<HTMLDivElement>(null);

useEffect(() => {
scrollRef.current?.scrollIntoView({ block: 'nearest' });
});

function openEditMode() {
openEditableCell();
}
Expand Down Expand Up @@ -52,7 +58,11 @@ export function EditableCellSoftFocusMode({ children }: OwnProps) {
}

return (
<EditableCellDisplayContainer onClick={handleClick} softFocus>
<EditableCellDisplayContainer
onClick={handleClick}
softFocus
scrollRef={scrollRef}
>
{children}
</EditableCellDisplayContainer>
);
Expand Down

0 comments on commit 700b567

Please sign in to comment.