Skip to content

Added support for the custom scrollParent for the scrollIntoView #197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

oleksandr-danylchenko
Copy link
Contributor

@oleksandr-danylchenko oleksandr-danylchenko commented Apr 15, 2025

Issue

The scrollIntoView is great and convenient in most cases, especially if you need to scroll to the annotation on load of the page. Thanks!

However, I our mobile app that uses Ionic components library, we faced an edge case with the getScrollParent. The Ionic handles a scrollable content in a bit of a peculiar way. It uses #shadow-dom to hide the "inner-scroll" scrollable element, but its "public" elements all have the overflow: visible1
CleanShot 2025-04-15 at 12 36 13

Therefore, if we render the text-annotator over such content, the scrollIntoView will be ineffective, operating over non-scrollable elements 🤷🏻‍♂️

Changes Made

Added support for providing a custom scrollParent to overcome the sensible limitations of the getScrollParent.

(Soomo Staged)

Footnotes

  1. https://ionicframework.com/docs/api/content#scroll-methods


// Position of the annotation relative to viewport
// Note: first selector is not necessarily top one...
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line seems contradictory to the following one 😅

// The 1st selector is the topmost one as well
const { range } = current.target.selector[0];

@oleksandr-danylchenko
Copy link
Contributor Author

oleksandr-danylchenko commented Apr 15, 2025

Also, due to such scroll handling in Ionic, I needed to add the following redraw workaround:

const AnnotatorScrollRedraw: FC<Pick<Props, 'scrollElement'>> = (props) => {
	const { scrollElement } = props;

	const r = useAnnotator();

	useEffect(() => {
		if (!scrollElement || !r) return;

		const handleScroll = () => r.redraw(true);
		scrollElement.addEventListener('scroll', handleScroll, { capture: true, passive: true });

		return () => scrollElement.removeEventListener('scroll', handleScroll);
	}, [scrollElement, r]);

	return null;
};

(See #104)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant