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

Add the ability to disable block selection clearing #44508

Closed
joshuatf opened this issue Sep 27, 2022 · 1 comment · Fixed by #44517
Closed

Add the ability to disable block selection clearing #44508

joshuatf opened this issue Sep 27, 2022 · 1 comment · Fixed by #44517
Assignees
Labels
[Package] Block editor /packages/block-editor [Type] Enhancement A suggestion for improvement.

Comments

@joshuatf
Copy link
Contributor

What problem does this address?

Building a rich text editor solution based on the block editor can lead to unexpected interactions. On deselection of a block, we lose the toolbar and UI for the text editor.

This would be useful so that WooCommerce can use the block based editor for its new rich text editor solution.

Before deselection:
Screen Shot 2022-09-26 at 12 57 40 PM

After deselection
Screen Shot 2022-09-26 at 12 57 46 PM

What is your proposed solution?

If we can prevent clearing of items in some way, that would be ideal. This could either be through a prop or simply handling the deselection on click instead of mousedown so we can revert deselection in the consuming component.

export function useBlockSelectionClearer() {
const { hasSelectedBlock, hasMultiSelection } =
useSelect( blockEditorStore );
const { clearSelectedBlock } = useDispatch( blockEditorStore );
return useRefEffect(
( node ) => {
function onMouseDown( event ) {
if ( ! hasSelectedBlock() && ! hasMultiSelection() ) {
return;
}
// Only handle clicks on the element, not the children.
if ( event.target !== node ) {
return;
}
clearSelectedBlock();
}
node.addEventListener( 'mousedown', onMouseDown );
return () => {
node.removeEventListener( 'mousedown', onMouseDown );
};
},
[ hasSelectedBlock, hasMultiSelection, clearSelectedBlock ]
);
}

@github-actions
Copy link

Help us move this issue forward. This issue is being marked stale since it has no activity after 15 days of requesting more information. Please add info requested so we can help move the issue forward. Note: The triage policy is to close stale issues that need more info and no response after 2 weeks.

@github-actions github-actions bot added the [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. label Oct 13, 2022
@talldan talldan removed the [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. label Oct 13, 2022
@priethor priethor removed the [Status] In Progress Tracking issues with work in progress label Nov 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Block editor /packages/block-editor [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants