How to use the @wordpress/dom.getScrollContainer function in @wordpress/dom

To help you get started, we’ve selected a few @wordpress/dom examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github front / gutenberg-js / src / js / gutenberg-overrides / packages / editor / build-module / components / rich-text / index.js View on Github external
scrollToRect (rect) {
    const { top: caretTop } = rect;
    const container = getScrollContainer(this.editor.getBody());

    if (! container) {
      return;
    }

    // When scrolling, avoid positioning the caret at the very top of
    // the viewport, providing some "air" and some textual context for
    // the user, and avoiding toolbars.
    const graceOffset = 100;

    // Avoid pointless scrolling by establishing a threshold under
    // which scrolling should be skipped;
    const epsilon = 10;
    const delta = caretTop - graceOffset;

    if (Math.abs(delta) > epsilon) {
github WordPress / gutenberg / editor / components / rich-text / index.js View on Github external
scrollToRect( rect ) {
		const { top: caretTop } = rect;
		const container = getScrollContainer( this.editor.getBody() );

		if ( ! container ) {
			return;
		}

		// When scrolling, avoid positioning the caret at the very top of
		// the viewport, providing some "air" and some textual context for
		// the user, and avoiding toolbars.
		const graceOffset = 100;

		// Avoid pointless scrolling by establishing a threshold under
		// which scrolling should be skipped;
		const epsilon = 10;
		const delta = caretTop - graceOffset;

		if ( Math.abs( delta ) > epsilon ) {
github WordPress / gutenberg / packages / components / src / popover / utils.js View on Github external
const { height } = contentSize;

	if ( sticky ) {
		let topEl = anchorRef;
		let bottomEl = anchorRef;

		if ( typeof sticky === 'string' ) {
			const elements = document.querySelectorAll( sticky );

			if ( elements.length ) {
				topEl = elements[ 0 ];
				bottomEl = elements[ elements.length - 1 ];
			}
		}

		const scrollContainerEl = getScrollContainer( topEl ) || document.body;
		const scrollRect = scrollContainerEl.getBoundingClientRect();
		const topRect = topEl.getBoundingClientRect();
		const bottomRect = bottomEl.getBoundingClientRect();

		if ( topRect.top - height <= scrollRect.top ) {
			return {
				yAxis,
				popoverTop: Math.min( bottomRect.bottom, scrollRect.top + height ),
			};
		}
	}

	// y axis alignment choices
	let anchorMidPoint = anchorRect.top + ( anchorRect.height / 2 );

	if ( corner === 'bottom' ) {
github WordPress / gutenberg / editor / components / rich-text / index.js View on Github external
scrollToRect( rect ) {
		const { top: caretTop } = rect;
		const container = getScrollContainer( this.editor.getBody() );

		if ( ! container ) {
			return;
		}

		// When scrolling, avoid positioning the caret at the very top of
		// the viewport, providing some "air" and some textual context for
		// the user, and avoiding toolbars.
		const graceOffset = 100;

		// Avoid pointless scrolling by establishing a threshold under
		// which scrolling should be skipped;
		const epsilon = 10;
		const delta = caretTop - graceOffset;

		if ( Math.abs( delta ) > epsilon ) {
github WordPress / gutenberg / packages / block-editor / src / components / preserve-scroll-in-reorder / index.js View on Github external
restorePreviousOffset( offset ) {
		const { selectionStart } = this.props;
		const blockNode = getBlockDOMNode( selectionStart );
		if ( blockNode ) {
			const scrollContainer = getScrollContainer( blockNode );
			if ( scrollContainer ) {
				scrollContainer.scrollTop = scrollContainer.scrollTop +
					blockNode.getBoundingClientRect().top - offset;
			}
		}
	}
github WordPress / gutenberg / editor / components / preserve-scroll-in-reorder / index.js View on Github external
restorePreviousOffset( offset ) {
		const { selectionStart } = this.props;
		const blockNode = getBlockDOMNode( selectionStart );
		if ( blockNode ) {
			const scrollContainer = getScrollContainer( blockNode );
			if ( scrollContainer ) {
				scrollContainer.scrollTop = scrollContainer.scrollTop +
					blockNode.getBoundingClientRect().top - offset;
			}
		}
	}