Skip to content

Commit

Permalink
fix: scroll into view link
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Oct 4, 2024
1 parent 4036239 commit a7a64ae
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/components/ScrollIntoViewLink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { type FC } from "react"
import { Link, type LinkProps } from "@mui/material"

export interface ScrollIntoViewLinkProps extends Omit<LinkProps, "onClick"> {
elementId: string
options?: ScrollIntoViewOptions
}

const ScrollIntoViewLink: FC<ScrollIntoViewLinkProps> = ({
elementId,
options,
...linkProps
}) => (
<Link
{...linkProps}
onClick={() => {
const element = document.getElementById(elementId)
element?.scrollIntoView(options)
}}
/>
)

export default ScrollIntoViewLink
2 changes: 2 additions & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit a7a64ae

Please sign in to comment.