Skip to content
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

Multi select: remove unneeded scrolling #18972

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/block-editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ Undocumented declaration.

<a name="MultiSelectScrollIntoView" href="#MultiSelectScrollIntoView">#</a> **MultiSelectScrollIntoView**

Undocumented declaration.
Deprecated component.

<a name="NavigableToolbar" href="#NavigableToolbar">#</a> **NavigableToolbar**

Expand Down
Original file line number Diff line number Diff line change
@@ -1,68 +1,6 @@
/**
* External dependencies
* Deprecated component.
*/
import scrollIntoView from 'dom-scroll-into-view';

/**
* WordPress dependencies
*/
import { Component } from '@wordpress/element';
import { withSelect } from '@wordpress/data';
import { getScrollContainer } from '@wordpress/dom';

/**
* Internal dependencies
*/
import { getBlockDOMNode } from '../../utils/dom';

class MultiSelectScrollIntoView extends Component {
componentDidUpdate() {
// Relies on expectation that `componentDidUpdate` will only be called
// if value of `extentClientId` changes.
this.scrollIntoView();
}

/**
* Ensures that if a multi-selection exists, the extent of the selection is
* visible within the nearest scrollable container.
*/
scrollIntoView() {
const { extentClientId, isMultiSelecting } = this.props;
if ( ! extentClientId || isMultiSelecting ) {
return;
}

const extentNode = getBlockDOMNode( extentClientId );
if ( ! extentNode ) {
return;
}

const scrollContainer = getScrollContainer( extentNode );

// If there's no scroll container, it follows that there's no scrollbar
// and thus there's no need to try to scroll into view.
if ( ! scrollContainer ) {
return;
}

scrollIntoView( extentNode, scrollContainer, {
onlyScrollIfNeeded: true,
} );
}

render() {
return null;
}
export default function MultiSelectScrollIntoView() {
return null;
}

export default withSelect( ( select ) => {
const {
getLastMultiSelectedBlockClientId,
isMultiSelecting,
} = select( 'core/block-editor' );

return {
extentClientId: getLastMultiSelectedBlockClientId(),
isMultiSelecting: isMultiSelecting(),
};
} )( MultiSelectScrollIntoView );
2 changes: 0 additions & 2 deletions packages/edit-post/src/components/visual-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
BlockList,
CopyHandler,
BlockSelectionClearer,
MultiSelectScrollIntoView,
__experimentalBlockSettingsMenuFirstItem,
__experimentalBlockSettingsMenuPluginsExtension,
} from '@wordpress/block-editor';
Expand All @@ -27,7 +26,6 @@ function VisualEditor() {
return (
<BlockSelectionClearer className="edit-post-visual-editor editor-styles-wrapper">
<VisualEditorGlobalKeyboardShortcuts />
<MultiSelectScrollIntoView />
<Typewriter>
<WritingFlow>
<ObserveTyping>
Expand Down