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 v2]: Fix outdent on empty list item if we press enter #40939

Merged
merged 1 commit into from
May 10, 2022
Merged
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
10 changes: 5 additions & 5 deletions packages/block-library/src/list-item/hooks/use-enter.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { store as blockEditorStore } from '@wordpress/block-editor';
/**
* Internal dependencies
*/
import useIndentListItem from './use-indent-list-item';
import useOutdentListItem from './use-outdent-list-item';

export default function useEnter( props ) {
const { replaceBlocks } = useDispatch( blockEditorStore );
Expand All @@ -27,7 +27,7 @@ export default function useEnter( props ) {
} = useSelect( blockEditorStore );
const propsRef = useRef( props );
propsRef.current = props;
const [ canIndent, indentListItem ] = useIndentListItem(
const [ canOutdent, outdentListItem ] = useOutdentListItem(
propsRef.current.clientId
);
return useRefEffect(
Expand All @@ -41,8 +41,8 @@ export default function useEnter( props ) {
return;
}
event.preventDefault();
if ( canIndent ) {
indentListItem();
if ( canOutdent ) {
outdentListItem();
return;
}
// Here we are in top level list so we need to split.
Expand Down Expand Up @@ -89,6 +89,6 @@ export default function useEnter( props ) {
element.removeEventListener( 'keydown', onKeyDown );
};
},
[ canIndent ]
[ canOutdent ]
);
}