themesberg / flowbite-react

Official React components built for Flowbite and Tailwind CSS
https://flowbite-react.com
MIT License
1.86k stars 416 forks source link

Programatically Scroll Modal.Body to the top #1275

Open schellenbergk opened 7 months ago

schellenbergk commented 7 months ago

Summary

I tried:

// reset scroll:
  const modalBody = useRef<HTMLDivElement>(null);
  useEffect(() => {
    if (modalBody.current) modalBody!.current!.scrollTop = 0;
  }, [trigger, modalBody]);
  ...
  <Modal.Body
          className="p-0 min-h-[300px] aspect-[30/13]"
          ref={modalBody}
        >...

but ref is not being passed.

SutuSebastian commented 7 months ago

Good catch, solution here is to have every single component (and its sub-components, if any) forward ref.