Skip to content

Commit

Permalink
only apply z-index if negative margins are present
Browse files Browse the repository at this point in the history
  • Loading branch information
MaggieCabrera authored and scruffian committed Apr 16, 2024
1 parent d537663 commit d61abd4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/base-styles/_z-index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

$z-layers: (
".block-editor-block-list__block::before": 0,
".block-editor-block-list__block.is-selected": 1,
".block-editor-block-list__block.is-selected": 20,
".block-editor-block-switcher__arrow": 1,
".block-editor-block-list__block {core/image aligned wide or fullwide}": 20,
".block-library-classic__toolbar": 31, // When scrolled to top this toolbar needs to sit over block-editor-block-toolbar
Expand Down
10 changes: 6 additions & 4 deletions packages/block-editor/src/components/block-list/content.scss
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,12 @@ _::-webkit-full-page-media, _:future, :root .has-multi-selection .block-editor-b
user-select: none;
}

&.is-selected,
&.has-child-selected {
// Bring the selected block forward so we can see it.
z-index: z-index(".block-editor-block-list__block.is-selected");
&.has-negative-margin {
&.is-selected,
&.has-child-selected {
// Bring the selected block forward so we can see it.
z-index: z-index(".block-editor-block-list__block.is-selected");
}
}

.reusable-block-edit-panel * {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@ export function useBlockProps( props = {}, { __unstableIsHtml } = {} ) {
);
}

let hasNegativeMargin = false;
if (
wrapperProps?.style?.marginTop?.charAt( 0 ) === '-' ||
wrapperProps?.style?.marginBottom?.charAt( 0 ) === '-' ||
wrapperProps?.style?.marginLeft?.charAt( 0 ) === '-' ||
wrapperProps?.style?.marginRight?.charAt( 0 ) === '-'
) {
hasNegativeMargin = true;
}

return {
tabIndex: blockEditingMode === 'disabled' ? -1 : 0,
...wrapperProps,
Expand Down Expand Up @@ -174,6 +184,7 @@ export function useBlockProps( props = {}, { __unstableIsHtml } = {} ) {
'can-insert-moving-block': canInsertMovingBlock,
'is-editing-disabled': isEditingDisabled,
'has-editable-outline': hasEditableOutline,
'has-negative-margin': hasNegativeMargin,
'is-content-locked-temporarily-editing-as-blocks':
isTemporarilyEditingAsBlocks,
},
Expand Down

0 comments on commit d61abd4

Please sign in to comment.