From a7a64ae674befc766e9ecc51e245d4502d00e8bd Mon Sep 17 00:00:00 2001 From: SKairinos Date: Fri, 4 Oct 2024 14:23:41 +0000 Subject: [PATCH] fix: scroll into view link --- src/components/ScrollIntoViewLink.tsx | 23 +++++++++++++++++++++++ src/components/index.ts | 2 ++ 2 files changed, 25 insertions(+) create mode 100644 src/components/ScrollIntoViewLink.tsx diff --git a/src/components/ScrollIntoViewLink.tsx b/src/components/ScrollIntoViewLink.tsx new file mode 100644 index 0000000..8b6ffd6 --- /dev/null +++ b/src/components/ScrollIntoViewLink.tsx @@ -0,0 +1,23 @@ +import { type FC } from "react" +import { Link, type LinkProps } from "@mui/material" + +export interface ScrollIntoViewLinkProps extends Omit { + elementId: string + options?: ScrollIntoViewOptions +} + +const ScrollIntoViewLink: FC = ({ + elementId, + options, + ...linkProps +}) => ( + { + const element = document.getElementById(elementId) + element?.scrollIntoView(options) + }} + /> +) + +export default ScrollIntoViewLink diff --git a/src/components/index.ts b/src/components/index.ts index b54e67c..14e7e2c 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -14,6 +14,8 @@ export * from "./ItemizedList" export { default as ItemizedList } from "./ItemizedList" export * from "./OrderedGrid" export { default as OrderedGrid } from "./OrderedGrid" +export * from "./ScrollIntoViewLink" +export { default as ScrollIntoViewLink } from "./ScrollIntoViewLink" export * from "./SyncError" export { default as SyncError } from "./SyncError" export * from "./TablePagination"