Files
supabase/apps/studio/components/ui/AIAssistantPanel/DropdownScrollArea.tsx
Joshen Lim f521109ce2 Chore/database functions v2 (#29969)
* Init AiAssistantPanel

* Temp

* Temp

* iterating on assistant ux

* More spiking

* Tweaking...

* Moar tweaking..

* Even more tweaking

* Tweek

* More tweaks

* Final tweaking...

* TWEAK

* Spelling

* Fix

* Assistant error handling and small bug fix in context for message

* Add feature flag

* Fix

* Address all feedback

* Minor
2024-10-23 16:43:38 +08:00

37 lines
1.1 KiB
TypeScript

import { PropsWithChildren, useEffect } from 'react'
import { ScrollArea } from 'ui'
interface DropdownScrollAreaProps {
id?: string
className?: string
}
// [Joshen] This is a temporary solution to a really odd behavior i've observed with the components in Shadcn
// Specifically if we're using a ScrollArea (or even just anything with overflow) within a DropdownMenu, within a Sheet
// The mouse wheel event to scroll in the ScrollArea is somehow getting ignored in this specific context, hence the fix here
export const DropdownScrollArea = ({
id,
className,
children,
}: PropsWithChildren<DropdownScrollAreaProps>) => {
useEffect(() => {
const scrollFix = (e: WheelEvent) => e.stopPropagation()
if (id) {
const el = document.getElementById(id)
if (el) {
el.addEventListener('wheel', scrollFix, { passive: false })
return () => el.removeEventListener('wheel', scrollFix)
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
return (
<ScrollArea id={id} className={className}>
{children}
</ScrollArea>
)
}