Closed gizemagden closed 2 months ago
I have a PR open for this. Passing through the scrollParent will be required to use callback functions in the future:
TableOfContents.configure({
// ...
scrollParent: () => scrollRef.current
})
Thank you, but unfortunately it still does not work correctly for me.
I noticed I needed to pass my scrollable div to the dependency array of the useEditor hook since it is set later. By doing that, I am able to see the onUpdate callback of the extension is called on scroll. But when I look at the isScrolledOver
and isActive
values of the headers, they seem to be set based on the viewport not on my scrollable parent element. How can I make sure that they are not calculated based on the viewport?
const editor = useEditor({
extensions: [...ExtensionsKit, TableOfContents.configure({
scrollParent: () => { console.log("Editor scrolling parent", editorScrollParent); return editorScrollParent as HTMLElement;},
onUpdate: (data: TableOfContentData, isCreate?: boolean) => {
console.log("Updated data", data, isCreate); // isScrolledOver and isActive values in here are not correct.
},
})],
content: "",
autofocus: true,
injectCSS: false,
editable: isEditOn,
}, [editorScrollParent]);
how did you fix it @gizemagden ?
Affected Packages
@tiptap-pro/extension-table-of-contents
Version(s)
2.9.2
Description of the Bug
I am using
TableOfContents
extension. I set a specific scrollParent element other than window.onUpdate
callback of the extension is not called when I scroll the scrollable parent div. So, I cannot access updatedisScrolledOver
andisActive
props of the anchors.I see when the whole page is scrollable, with the default setting (window),
onUpdate
is called.Browser Used
Chrome
Code Example (Preferred)
No response
Expected Behavior
onUpdate
callback of theTableOfContents
extension should be called properly when a specific scrollParent element is set.Additional Context (Optional)
Code:
Dependency Updates