Skip to content

Commit

Permalink
Prevent before input for multi-selection
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Aug 7, 2024
1 parent f1af39f commit 4b74ad5
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default function useInput() {
} = useDispatch( blockEditorStore );

return useRefEffect( ( node ) => {
function onBeforeInput() {
function onBeforeInput( event ) {
// If writing flow is editable, NEVER allow the browser to alter the
// DOM. This will cause React errors (and the DOM should only be
// altered in a controlled fashion).
Expand All @@ -56,13 +56,15 @@ export default function useInput() {
: null;
const root = getSelectionRoot( node.ownerDocument );

node.contentEditable = false;
if ( root ) {
node.contentEditable = false;
root.focus();
selection.removeAllRanges();
if ( range ) {
selection.addRange( range );
}
} else {
event.preventDefault();
}
}
}
Expand Down

0 comments on commit 4b74ad5

Please sign in to comment.