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

List View: Try a slightly more accurate and flexible approach for drag to top and bottom #50689

Closed
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
12 changes: 11 additions & 1 deletion packages/block-editor/src/components/list-view/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* External dependencies
*/
import classNames from 'classnames';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -59,6 +64,7 @@ export const BLOCK_LIST_ITEM_HEIGHT = 36;
* @param {Object} props Components props.
* @param {string} props.id An HTML element id for the root element of ListView.
* @param {Array} props.blocks _deprecated_ Custom subset of block client IDs to be used instead of the default hierarchy.
* @param {?string} props.className Optional class name to add to the TreeGrid element.
* @param {?boolean} props.showBlockMovers Flag to enable block movers. Defaults to `false`.
* @param {?boolean} props.isExpanded Flag to determine whether nested levels are expanded by default. Defaults to `false`.
* @param {?boolean} props.showAppender Flag to show or hide the block appender. Defaults to `false`.
Expand All @@ -73,6 +79,7 @@ function ListViewComponent(
{
id,
blocks,
className,
showBlockMovers = false,
isExpanded = false,
showAppender = false,
Expand Down Expand Up @@ -237,7 +244,10 @@ function ListViewComponent(
/>
<TreeGrid
id={ id }
className="block-editor-list-view-tree"
className={ classNames(
'block-editor-list-view-tree',
className
) }
aria-label={ __( 'Block navigation structure' ) }
ref={ treeGridRef }
onCollapseRow={ collapseRow }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,12 @@ export default function useListViewDropZone() {
const draggedBlockClientIds = getDraggedBlockClientIds();
const throttled = useThrottle(
useCallback(
( event, currentTarget ) => {
( event, currentTarget, action ) => {
if ( action === 'clear' ) {
setTarget( null );
return;
}

const position = { x: event.clientX, y: event.clientY };
const isBlockDrag = !! draggedBlockClientIds?.length;

Expand Down Expand Up @@ -433,6 +438,9 @@ export default function useListViewDropZone() {

const ref = useDropZone( {
onDrop: onBlockDrop,
onDragLeave( event ) {
throttled( event, event.currentTarget, 'clear' );
},
onDragOver( event ) {
// `currentTarget` is only available while the event is being
// handled, so get it now and pass it to the thottled function.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export default function ListViewSidebar() {
>
{ tab === 'list-view' && (
<div className="edit-post-editor__list-view-panel-content">
<ListView />
<ListView className="edit-post-editor__list-view-panel-content__list-view" />
</div>
) }
{ tab === 'outline' && <ListViewOutline /> }
Expand Down
12 changes: 12 additions & 0 deletions packages/edit-post/src/components/secondary-sidebar/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@
padding: $grid-unit-10 ($grid-unit-10 - $border-width - $border-width);
}

.edit-post-editor__list-view-panel-content {
padding: 0;
}

.edit-post-editor__list-view-panel-content__list-view {
padding: $grid-unit-10 ($grid-unit-10 - $border-width - $border-width);
// Override the border collapse set by the TreeGrid table.
// This is so that the panel's height and padding can take effect.
border-collapse: separate;
border-spacing: 0;
}

.edit-post-editor__list-view-empty-headings {
& > svg {
margin-top: $grid-unit-30 + $grid-unit-05;
Expand Down