Files
overleaf-cep/services/web/frontend/js/shared/components/notification-scrolled-to.tsx
T
Jessica Lawshe 66671f9bf2 Merge pull request #34936 from overleaf/jel-scroll-to-notification
[web] Scroll to new notification added above domains table

GitOrigin-RevId: f62851398de3a54ef07c0e125c65a29dd84af6f8
2026-09-17 11:33:41 +00:00

32 lines
847 B
TypeScript

import Notification, {
NotificationProps,
} from '@/shared/components/notification'
import { useEffect } from 'react'
import { elementIsInView } from '@/shared/utils/element-in-view'
function NotificationScrolledTo({ ...props }: NotificationProps) {
useEffect(() => {
if (props.id) {
const alert = document.getElementById(props.id)
if (alert && !elementIsInView(alert)) {
alert.scrollIntoView({ behavior: 'smooth' })
}
}
}, [props])
const notificationProps = { ...props }
if (!notificationProps.className) {
notificationProps.className = ''
}
notificationProps.className = `${notificationProps.className} notification-with-scroll-margin`
return (
<div className="notification-list">
<Notification {...notificationProps} />
</div>
)
}
export default NotificationScrolledTo