Uncollapse widget area when block is dragged over #25992
Conversation
) } | ||
</PanelBody> | ||
</Panel> | ||
<div onDragOver={ openOnDragOver }> |
adamziel
Oct 9, 2020
•
Author
Contributor
There are already a few blank <div/>
elements in the tree so this shouldn't break anything. An alternative would be to do <Panel onDragOver={ openOnDragOver }>
and then update <Panel />
to apply arbitrary properties to its root element, thoughts?
There are already a few blank <div/>
elements in the tree so this shouldn't break anything. An alternative would be to do <Panel onDragOver={ openOnDragOver }>
and then update <Panel />
to apply arbitrary properties to its root element, thoughts?
talldan
Oct 12, 2020
Contributor
Yep, I think this is ok.
Another alternative would be <Panel openOnDragOver>
making the behavior implicit to Panel. Though I think given PanelBody is more of a controlled component it's better to keep it explicit like you have it here.
Yep, I think this is ok.
Another alternative would be <Panel openOnDragOver>
making the behavior implicit to Panel. Though I think given PanelBody is more of a controlled component it's better to keep it explicit like you have it here.
talldan
Oct 13, 2020
•
Contributor
Actually, I realise there's some block CSS that might need to be adjusted (though it's currently broken anyway)
Actually, I realise there's some block CSS that might need to be adjusted (though it's currently broken anyway)
Size Change: +317 B (0%) Total Size: 1.19 MB
|
Filename | Size | Change | |
---|---|---|---|
build/a11y/index.js |
1.14 kB | 0 B | |
build/annotations/index.js |
3.54 kB | 0 B | |
build/api-fetch/index.js |
3.35 kB | 0 B | |
build/autop/index.js |
2.72 kB | 0 B | |
build/blob/index.js |
668 B | 0 B | |
build/block-directory/index.js |
8.6 kB | 0 B | |
build/block-directory/style-rtl.css |
943 B | 0 B | |
build/block-directory/style.css |
942 B | 0 B | |
build/block-editor/index.js |
130 kB | 0 B | |
build/block-editor/style-rtl.css |
11 kB | 0 B | |
build/block-editor/style.css |
10.9 kB | 0 B | |
build/block-library/editor-rtl.css |
8.93 kB | 0 B | |
build/block-library/editor.css |
8.93 kB | 0 B | |
build/block-library/index.js |
144 kB | 0 B | |
build/block-library/style-rtl.css |
7.71 kB | 0 B | |
build/block-library/style.css |
7.71 kB | 0 B | |
build/block-library/theme-rtl.css |
741 B | 0 B | |
build/block-library/theme.css |
741 B | 0 B | |
build/block-serialization-default-parser/index.js |
1.77 kB | 0 B | |
build/block-serialization-spec-parser/index.js |
3.1 kB | 0 B | |
build/blocks/index.js |
47.6 kB | 0 B | |
build/components/style-rtl.css |
15.4 kB | 0 B | |
build/components/style.css |
15.4 kB | 0 B | |
build/compose/index.js |
9.63 kB | 0 B | |
build/core-data/index.js |
12.1 kB | 0 B | |
build/data-controls/index.js |
683 B | 0 B | |
build/data/index.js |
8.63 kB | 0 B | |
build/date/index.js |
31.9 kB | 0 B | |
build/deprecated/index.js |
772 B | 0 B | |
build/dom-ready/index.js |
569 B | 0 B | |
build/dom/index.js |
4.43 kB | 0 B | |
build/edit-navigation/index.js |
10.6 kB | 0 B | |
build/edit-navigation/style-rtl.css |
868 B | 0 B | |
build/edit-navigation/style.css |
871 B | 0 B | |
build/edit-post/index.js |
306 kB | 0 B | |
build/edit-post/style-rtl.css |
6.37 kB | 0 B | |
build/edit-post/style.css |
6.35 kB | 0 B | |
build/edit-site/index.js |
21.6 kB | 0 B | |
build/edit-site/style-rtl.css |
3.8 kB | 0 B | |
build/edit-site/style.css |
3.81 kB | 0 B | |
build/edit-widgets/style-rtl.css |
3.09 kB | 0 B | |
build/edit-widgets/style.css |
3.09 kB | 0 B | |
build/editor/editor-styles-rtl.css |
480 B | 0 B | |
build/editor/editor-styles.css |
482 B | 0 B | |
build/editor/index.js |
42.6 kB | 0 B | |
build/editor/style-rtl.css |
3.85 kB | 0 B | |
build/editor/style.css |
3.84 kB | 0 B | |
build/element/index.js |
4.45 kB | 0 B | |
build/escape-html/index.js |
733 B | 0 B | |
build/format-library/index.js |
7.49 kB | 0 B | |
build/format-library/style-rtl.css |
547 B | 0 B | |
build/format-library/style.css |
548 B | 0 B | |
build/hooks/index.js |
1.74 kB | 0 B | |
build/html-entities/index.js |
622 B | 0 B | |
build/i18n/index.js |
3.54 kB | 0 B | |
build/is-shallow-equal/index.js |
709 B | 0 B | |
build/keyboard-shortcuts/index.js |
2.38 kB | 0 B | |
build/keycodes/index.js |
1.85 kB | 0 B | |
build/list-reusable-blocks/index.js |
3.02 kB | 0 B | |
build/list-reusable-blocks/style-rtl.css |
476 B | 0 B | |
build/list-reusable-blocks/style.css |
476 B | 0 B | |
build/media-utils/index.js |
5.12 kB | 0 B | |
build/notices/index.js |
1.69 kB | 0 B | |
build/nux/index.js |
3.27 kB | 0 B | |
build/nux/style-rtl.css |
671 B | 0 B | |
build/nux/style.css |
668 B | 0 B | |
build/plugins/index.js |
2.44 kB | 0 B | |
build/primitives/index.js |
1.35 kB | 0 B | |
build/priority-queue/index.js |
789 B | 0 B | |
build/redux-routine/index.js |
2.85 kB | 0 B | |
build/reusable-blocks/index.js |
3.04 kB | 0 B | |
build/rich-text/index.js |
13 kB | 0 B | |
build/server-side-render/index.js |
2.61 kB | 0 B | |
build/shortcode/index.js |
1.7 kB | 0 B | |
build/token-list/index.js |
1.24 kB | 0 B | |
build/url/index.js |
4.06 kB | 0 B | |
build/viewport/index.js |
1.75 kB | 0 B | |
build/warning/index.js |
1.13 kB | 0 B | |
build/wordcount/index.js |
1.17 kB | 0 B |
@paaljoachim my thoughts exactly! That's what I meant by asking:
If the user wants to drag the widget from sidebar number 1 to sidebar 8, the current jerk will make it pretty hard so I think we should indicate that the area is about to open, but still give user a chance to keep dragging. I'm not sure how that indication would look like, hence I pinged @mapk :-) |
@paaljoachim I think your suggestion to makes collapsing/uncollapsing smooth would make a great feature not just here, but also for the Panel component. |
[ clientId ] | ||
); | ||
const { setIsWidgetAreaOpen } = useDispatch( 'core/edit-widgets' ); | ||
const openOnDragOver = useCallback( () => { | ||
if ( ! isOpen && isDraggingBlocks ) { |
talldan
Oct 12, 2020
Contributor
I don't think we should worry about isDraggingBlocks
, it should also open for dragged files and HTML so that users can upload/add things like images that way.
I don't think we should worry about isDraggingBlocks
, it should also open for dragged files and HTML so that users can upload/add things like images that way.
) } | ||
</PanelBody> | ||
</Panel> | ||
<div onDragOver={ openOnDragOver }> |
talldan
Oct 12, 2020
Contributor
Yep, I think this is ok.
Another alternative would be <Panel openOnDragOver>
making the behavior implicit to Panel. Though I think given PanelBody is more of a controlled component it's better to keep it explicit like you have it here.
Yep, I think this is ok.
Another alternative would be <Panel openOnDragOver>
making the behavior implicit to Panel. Though I think given PanelBody is more of a controlled component it's better to keep it explicit like you have it here.
Hey
I don't think we need an indicator necessarily. The expansion of the area seems to be a sufficient. Moving the dragged block into a collapsed area should open it but retain its positioning on screen and not jump to a particular point. Dragging it back out of the area should collapse that area again. I like how it works in the Classic Widget screen that Paal shared. When opening up an area on drag, the blue line drop indicator should appear above any existing widgets in that area if the user is dragging downward from one area to another area below. This should reverse when dragging up from an area below to an area above. |
There is some similar code in the navigation-link block that might be reusable (cc @kevin940726), but still think this works well enough as a first iteration. |
I think it's nearly there, the last part is smooth panel animation - let's make it a separate PR. |
* | ||
* @return {boolean} Is dragging within the target element. | ||
*/ | ||
const useIsDraggingWithin = ( elementRef ) => { |
adamziel
Oct 13, 2020
Author
Contributor
I just copied that over from edit-navigation
- happy to move it to another package if there are any good candidates.
I just copied that over from edit-navigation
- happy to move it to another package if there are any good candidates.
talldan
Oct 19, 2020
Contributor
Seems fine to duplicate it for now 👍
Seems fine to duplicate it for now
// Ref is used so that the effect does not re-run upon scrollAfterOpen changing value | ||
const scrollAfterOpenRef = useRef(); | ||
scrollAfterOpenRef.current = scrollAfterOpen; |
adamziel
Oct 13, 2020
Author
Contributor
This seems hackish - any better ideas?
This seems hackish - any better ideas?
talldan
Oct 19, 2020
Contributor
Yeah, not sure really. 🤔
Yeah, not sure really.
} else if ( ! isDraggingWithin && isOpen && openedWhileDragging ) { | ||
timeout = setTimeout( () => { | ||
setOpen( false ); | ||
}, 100 ); |
adamziel
Oct 13, 2020
Author
Contributor
Completely arbitrary timeouts
Completely arbitrary timeouts
talldan
Oct 19, 2020
•
Contributor
I'm personally finding the delays are unhelpful. The problem is that there's no indication anything is about to happen when I first drag over, and also the way the page scrolls while dragging means it's quite easy to zoom past an area.
The sidebars for the old widget page open immediately, so I think we can replicate that for now and revisit this. I took the liberty of pushing a commit to do that.
I'm personally finding the delays are unhelpful. The problem is that there's no indication anything is about to happen when I first drag over, and also the way the page scrolls while dragging means it's quite easy to zoom past an area.
The sidebars for the old widget page open immediately, so I think we can replicate that for now and revisit this. I took the liberty of pushing a commit to do that.
Testing this, I'm still unable to drag a widget into an empty widget area. Even though the empty now opens when dragged over, there's no drop indicator and dropping a widget on it doesn't work. How easy would it be to fix it in this PR? Or better to open another issue? |
@tellthemachines The fix was only recently merged - #26051 It's either that this PR needs to be rebased, or it might also need to be updated to account for the selectors mentioned here: |
I tested this and for me it did not work. |
I tested again. Either I am not testing correctly as it seems to be showing an older commit. This is what I see: There is still a jumpiness when dragging from one widget area to another. As it jumps too far down. |
83919b5
to
04ef9a5
I've rebased and double-checked the fix from #26051 still works, which it does I'm personally not seeing any sudden jumps with the latest code, but noticed a separate issue. The scroll while dragging behavior that the block editor has isn't particularly great with panels. What happens is that when a panel opens while dragging over it, suddenly there's more space that the page can scroll into. Not sure what to do about that, but it's definitely separate to this. Let's merge and then iterate to improve it. |
const scrollAfterOpenRef = useRef(); | ||
scrollAfterOpenRef.current = scrollAfterOpen; |
ZebulanStanphill
Oct 19, 2020
Member
I think this could be simplified to:
Suggested change
const scrollAfterOpenRef = useRef();
scrollAfterOpenRef.current = scrollAfterOpen;
const scrollAfterOpenRef = useRef( scrollAfterOpen );
And yeah, this definitely feels like a code smell.
I think this could be simplified to:
const scrollAfterOpenRef = useRef(); | |
scrollAfterOpenRef.current = scrollAfterOpen; | |
const scrollAfterOpenRef = useRef( scrollAfterOpen ); |
And yeah, this definitely feels like a code smell.
adamziel commentedOct 9, 2020
Description
Solves #25243
I wonder if we should add a timeout and some indication that the widget area is about to uncollapse @mapk ?
How has this been tested?
Types of changes
New feature (non-breaking change which adds functionality)
Checklist: