diff --git a/packages/block-editor/src/components/inspector-controls-tabs/use-inspector-controls-tabs.js b/packages/block-editor/src/components/inspector-controls-tabs/use-inspector-controls-tabs.js
index fbe072fab11c58..bf7f61de4c8cb7 100644
--- a/packages/block-editor/src/components/inspector-controls-tabs/use-inspector-controls-tabs.js
+++ b/packages/block-editor/src/components/inspector-controls-tabs/use-inspector-controls-tabs.js
@@ -43,6 +43,7 @@ export default function useInspectorControlsTabs( blockName ) {
default: defaultGroup,
dimensions: dimensionsGroup,
list: listGroup,
+ position: positionGroup,
typography: typographyGroup,
} = InspectorControlsGroups;
@@ -71,6 +72,7 @@ export default function useInspectorControlsTabs( blockName ) {
// or Advanced Controls slot, then add this tab.
const settingsFills = [
...( useSlotFills( defaultGroup.Slot.__unstableName ) || [] ),
+ ...( useSlotFills( positionGroup.Slot.__unstableName ) || [] ),
...( useSlotFills( InspectorAdvancedControls.slotName ) || [] ),
];
diff --git a/packages/block-editor/src/components/inspector-controls/groups.js b/packages/block-editor/src/components/inspector-controls/groups.js
index cb03c1ff13fa57..46fca564925aa6 100644
--- a/packages/block-editor/src/components/inspector-controls/groups.js
+++ b/packages/block-editor/src/components/inspector-controls/groups.js
@@ -10,6 +10,7 @@ const InspectorControlsColor = createSlotFill( 'InspectorControlsColor' );
const InspectorControlsDimensions = createSlotFill(
'InspectorControlsDimensions'
);
+const InspectorControlsPosition = createSlotFill( 'InspectorControlsPosition' );
const InspectorControlsTypography = createSlotFill(
'InspectorControlsTypography'
);
@@ -23,6 +24,7 @@ const groups = {
dimensions: InspectorControlsDimensions,
list: InspectorControlsListView,
typography: InspectorControlsTypography,
+ position: InspectorControlsPosition,
};
export default groups;
diff --git a/packages/block-editor/src/hooks/position.js b/packages/block-editor/src/hooks/position.js
index bbaea07ddf035a..700686b9a6a7b8 100644
--- a/packages/block-editor/src/hooks/position.js
+++ b/packages/block-editor/src/hooks/position.js
@@ -8,11 +8,7 @@ import classnames from 'classnames';
*/
import { __, sprintf } from '@wordpress/i18n';
import { getBlockSupport, hasBlockSupport } from '@wordpress/blocks';
-import {
- BaseControl,
- CustomSelectControl,
- PanelBody,
-} from '@wordpress/components';
+import { BaseControl, CustomSelectControl } from '@wordpress/components';
import { createHigherOrderComponent, useInstanceId } from '@wordpress/compose';
import {
useContext,
@@ -295,10 +291,11 @@ export const withInspectorControls = createHigherOrderComponent(
return [
positionSupport && (
-
-
-
-
+
+
),
,
From 9148c63113cf33cb6eea929699cb5cdc79870b72 Mon Sep 17 00:00:00 2001
From: Andrew Serong <14988353+andrewserong@users.noreply.github.com>
Date: Thu, 15 Dec 2022 16:27:39 +1100
Subject: [PATCH 05/13] Roll in fix for toolbar position
---
.../src/components/block-popover/index.js | 29 +++++++++++
.../use-block-toolbar-popover-props.js | 50 ++++++++++++++++---
2 files changed, 73 insertions(+), 6 deletions(-)
diff --git a/packages/block-editor/src/components/block-popover/index.js b/packages/block-editor/src/components/block-popover/index.js
index 5382949684abd9..b84be381b82b61 100644
--- a/packages/block-editor/src/components/block-popover/index.js
+++ b/packages/block-editor/src/components/block-popover/index.js
@@ -7,6 +7,7 @@ import classnames from 'classnames';
* WordPress dependencies
*/
import { useMergeRefs } from '@wordpress/compose';
+import { getScrollContainer } from '@wordpress/dom';
import { Popover } from '@wordpress/components';
import {
forwardRef,
@@ -75,6 +76,34 @@ function BlockPopover(
};
}, [ selectedElement ] );
+ // Get the scrollable container that the block popover appears within.
+ const scrollContainer = useMemo( () => {
+ if ( ! __unstableContentRef?.current ) {
+ return;
+ }
+ return getScrollContainer( __unstableContentRef?.current );
+ }, [ __unstableContentRef?.current ] );
+
+ // Force the block popover to re-render whenever the content area is scrolled.
+ // This ensures that the position of the popover is accurate for fixed or sticky blocks.
+ useLayoutEffect( () => {
+ if ( ! scrollContainer ) {
+ return;
+ }
+
+ scrollContainer?.addEventListener?.(
+ 'scroll',
+ forceRecomputePopoverDimensions
+ );
+
+ return () => {
+ scrollContainer?.removeEventHandler?.(
+ 'scroll',
+ forceRecomputePopoverDimensions
+ );
+ };
+ }, [ scrollContainer ] );
+
const style = useMemo( () => {
if (
// popoverDimensionsRecomputeCounter is by definition always equal or greater
diff --git a/packages/block-editor/src/components/block-tools/use-block-toolbar-popover-props.js b/packages/block-editor/src/components/block-tools/use-block-toolbar-popover-props.js
index d218b1104139cf..4703e059855290 100644
--- a/packages/block-editor/src/components/block-tools/use-block-toolbar-popover-props.js
+++ b/packages/block-editor/src/components/block-tools/use-block-toolbar-popover-props.js
@@ -3,7 +3,13 @@
*/
import { useRefEffect } from '@wordpress/compose';
import { useSelect } from '@wordpress/data';
-import { useCallback, useLayoutEffect, useState } from '@wordpress/element';
+import { getScrollContainer } from '@wordpress/dom';
+import {
+ useCallback,
+ useLayoutEffect,
+ useMemo,
+ useState,
+} from '@wordpress/element';
/**
* Internal dependencies
@@ -40,24 +46,40 @@ const RESTRICTED_HEIGHT_PROPS = {
*
* @param {Element} contentElement The DOM element that represents the editor content or canvas.
* @param {Element} selectedBlockElement The outer DOM element of the first selected block.
+ * @param {Element} scrollContainer The scrollable container for the contentElement.
* @param {number} toolbarHeight The height of the toolbar in pixels.
*
* @return {Object} The popover props used to determine the position of the toolbar.
*/
-function getProps( contentElement, selectedBlockElement, toolbarHeight ) {
+function getProps(
+ contentElement,
+ selectedBlockElement,
+ scrollContainer,
+ toolbarHeight
+) {
if ( ! contentElement || ! selectedBlockElement ) {
return DEFAULT_PROPS;
}
+ // Get how far the content area has been scrolled.
+ const scrollTop = scrollContainer?.scrollTop || 0;
+
const blockRect = selectedBlockElement.getBoundingClientRect();
const contentRect = contentElement.getBoundingClientRect();
+ // Get the vertical position of top of the visible content area.
+ const topOfContentElementInViewport = scrollTop + contentRect.top;
+
// The document element's clientHeight represents the viewport height.
const viewportHeight =
contentElement.ownerDocument.documentElement.clientHeight;
- const hasSpaceForToolbarAbove =
- blockRect.top - contentRect.top > toolbarHeight;
+ // The restricted height area is calculated as the sum of the
+ // vertical position of the visible content area, plus the height
+ // of the block toolbar.
+ const restrictedTopArea = topOfContentElementInViewport + toolbarHeight;
+ const hasSpaceForToolbarAbove = blockRect.top > restrictedTopArea;
+
const isBlockTallerThanViewport =
blockRect.height > viewportHeight - toolbarHeight;
@@ -83,8 +105,19 @@ export default function useBlockToolbarPopoverProps( {
} ) {
const selectedBlockElement = useBlockElement( clientId );
const [ toolbarHeight, setToolbarHeight ] = useState( 0 );
+ const scrollContainer = useMemo( () => {
+ if ( ! contentElement ) {
+ return;
+ }
+ return getScrollContainer( contentElement );
+ }, [ contentElement ] );
const [ props, setProps ] = useState( () =>
- getProps( contentElement, selectedBlockElement, toolbarHeight )
+ getProps(
+ contentElement,
+ selectedBlockElement,
+ scrollContainer,
+ toolbarHeight
+ )
);
const blockIndex = useSelect(
( select ) => select( blockEditorStore ).getBlockIndex( clientId ),
@@ -98,7 +131,12 @@ export default function useBlockToolbarPopoverProps( {
const updateProps = useCallback(
() =>
setProps(
- getProps( contentElement, selectedBlockElement, toolbarHeight )
+ getProps(
+ contentElement,
+ selectedBlockElement,
+ scrollContainer,
+ toolbarHeight
+ )
),
[ contentElement, selectedBlockElement, toolbarHeight ]
);
From b4053c8f63bcb85c4cb403e0baca561df850cd84 Mon Sep 17 00:00:00 2001
From: Andrew Serong <14988353+andrewserong@users.noreply.github.com>
Date: Wed, 4 Jan 2023 16:46:49 +1100
Subject: [PATCH 06/13] Remove no longer needed change to block popover
---
.../src/components/block-popover/index.js | 29 -------------------
1 file changed, 29 deletions(-)
diff --git a/packages/block-editor/src/components/block-popover/index.js b/packages/block-editor/src/components/block-popover/index.js
index b84be381b82b61..5382949684abd9 100644
--- a/packages/block-editor/src/components/block-popover/index.js
+++ b/packages/block-editor/src/components/block-popover/index.js
@@ -7,7 +7,6 @@ import classnames from 'classnames';
* WordPress dependencies
*/
import { useMergeRefs } from '@wordpress/compose';
-import { getScrollContainer } from '@wordpress/dom';
import { Popover } from '@wordpress/components';
import {
forwardRef,
@@ -76,34 +75,6 @@ function BlockPopover(
};
}, [ selectedElement ] );
- // Get the scrollable container that the block popover appears within.
- const scrollContainer = useMemo( () => {
- if ( ! __unstableContentRef?.current ) {
- return;
- }
- return getScrollContainer( __unstableContentRef?.current );
- }, [ __unstableContentRef?.current ] );
-
- // Force the block popover to re-render whenever the content area is scrolled.
- // This ensures that the position of the popover is accurate for fixed or sticky blocks.
- useLayoutEffect( () => {
- if ( ! scrollContainer ) {
- return;
- }
-
- scrollContainer?.addEventListener?.(
- 'scroll',
- forceRecomputePopoverDimensions
- );
-
- return () => {
- scrollContainer?.removeEventHandler?.(
- 'scroll',
- forceRecomputePopoverDimensions
- );
- };
- }, [ scrollContainer ] );
-
const style = useMemo( () => {
if (
// popoverDimensionsRecomputeCounter is by definition always equal or greater
From 3fccfe498e0c669be72d552254748f137bf3309c Mon Sep 17 00:00:00 2001
From: Andrew Serong <14988353+andrewserong@users.noreply.github.com>
Date: Wed, 4 Jan 2023 16:53:12 +1100
Subject: [PATCH 07/13] Add scrollContainer to deps array
---
.../components/block-tools/use-block-toolbar-popover-props.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/packages/block-editor/src/components/block-tools/use-block-toolbar-popover-props.js b/packages/block-editor/src/components/block-tools/use-block-toolbar-popover-props.js
index 4703e059855290..08f71989df9a1c 100644
--- a/packages/block-editor/src/components/block-tools/use-block-toolbar-popover-props.js
+++ b/packages/block-editor/src/components/block-tools/use-block-toolbar-popover-props.js
@@ -138,7 +138,7 @@ export default function useBlockToolbarPopoverProps( {
toolbarHeight
)
),
- [ contentElement, selectedBlockElement, toolbarHeight ]
+ [ contentElement, selectedBlockElement, scrollContainer, toolbarHeight ]
);
// Update props when the block is moved. This also ensures the props are
From db57fefdd6a5758fc04346e6302a9df3f1566642 Mon Sep 17 00:00:00 2001
From: Andrew Serong <14988353+andrewserong@users.noreply.github.com>
Date: Thu, 5 Jan 2023 17:59:06 +1100
Subject: [PATCH 08/13] Remove redundant PHP code
---
lib/block-supports/position.php | 72 ---------------------------------
1 file changed, 72 deletions(-)
diff --git a/lib/block-supports/position.php b/lib/block-supports/position.php
index 17e34d995dc411..a2459274dcb931 100644
--- a/lib/block-supports/position.php
+++ b/lib/block-supports/position.php
@@ -25,78 +25,6 @@ function gutenberg_register_position_support( $block_type ) {
}
}
-/**
- * Generates the CSS for position support from the style object.
- *
- * @param string $selector CSS selector.
- * @param array $style Style object.
- * @return string CSS styles on success. Else, empty string.
- */
-function gutenberg_get_position_style( $selector, $style ) {
- $position_styles = array();
- $position_type = _wp_array_get( $style, array( 'position' ), '' );
-
- if (
- in_array( $position_type, array( 'fixed', 'sticky' ), true )
- ) {
- $sides = array( 'top', 'right', 'bottom', 'left' );
-
- foreach ( $sides as $side ) {
- $side_value = _wp_array_get( $style, array( 'position', $side ) );
- if ( null !== $side_value ) {
- /*
- * For fixed or sticky top positions,
- * ensure the value includes an offset for the logged in admin bar.
- */
- if (
- 'top' === $side &&
- ( 'fixed' === $position_type || 'sticky' === $position_type )
- ) {
- // Ensure 0 values can be used in `calc()` calculations.
- if ( '0' === $side_value || 0 === $side_value ) {
- $side_value = '0px';
- }
-
- // Ensure current side value also factors in the height of the logged in admin bar.
- $side_value = "calc($side_value + var(--wp-admin--admin-bar--height, 0px))";
- }
-
- $position_styles[] =
- array(
- 'selector' => "$selector",
- 'declarations' => array(
- $side => $side_value,
- ),
- );
- }
- }
-
- $position_styles[] =
- array(
- 'selector' => "$selector",
- 'declarations' => array(
- 'position' => $position_type,
- 'z-index' => '250', // TODO: This hard-coded value should live somewhere else.
- ),
- );
- }
-
- if ( ! empty( $position_styles ) ) {
- /*
- * Add to the style engine store to enqueue and render position styles.
- */
- return gutenberg_style_engine_get_stylesheet_from_css_rules(
- $position_styles,
- array(
- 'context' => 'block-supports',
- 'prettify' => false,
- )
- );
- }
-
- return '';
-}
-
/**
* Renders position styles to the block wrapper.
*
From 218acc276729ec3d0872a57682baabaf22621da0 Mon Sep 17 00:00:00 2001
From: Andrew Serong <14988353+andrewserong@users.noreply.github.com>
Date: Fri, 6 Jan 2023 15:20:06 +1100
Subject: [PATCH 09/13] Switch Static to Default, display help text after
selection, update text
---
packages/block-editor/src/hooks/position.js | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/packages/block-editor/src/hooks/position.js b/packages/block-editor/src/hooks/position.js
index 700686b9a6a7b8..f10c5d4fda7d2e 100644
--- a/packages/block-editor/src/hooks/position.js
+++ b/packages/block-editor/src/hooks/position.js
@@ -32,11 +32,10 @@ const OPTION_CLASSNAME =
'block-editor-hooks__position-selection__select-control__option';
const DEFAULT_OPTION = {
- key: 'static',
+ key: 'default',
value: '',
- name: __( 'Static' ),
+ name: __( 'Default' ),
className: OPTION_CLASSNAME,
- __experimentalHint: __( 'The default position' ),
};
const STICKY_OPTION = {
@@ -45,7 +44,7 @@ const STICKY_OPTION = {
name: __( 'Sticky' ),
className: OPTION_CLASSNAME,
__experimentalHint: __(
- 'The block will scroll with the document but stick instead of exiting the viewport'
+ 'The block will stick to the top of the window instead of scrolling.'
),
};
@@ -55,7 +54,7 @@ const FIXED_OPTION = {
name: __( 'Fixed' ),
className: OPTION_CLASSNAME,
__experimentalHint: __(
- 'The block will not move when the page is scrolled'
+ 'The block will not move when the page is scrolled.'
),
};
@@ -247,7 +246,10 @@ export function PositionEdit( props ) {
return Platform.select( {
web: (
<>
-
+
Date: Mon, 9 Jan 2023 11:24:44 +1100
Subject: [PATCH 10/13] Remove help text, update logic to gracefully handle
illegal values
---
packages/block-editor/src/hooks/position.js | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/packages/block-editor/src/hooks/position.js b/packages/block-editor/src/hooks/position.js
index f10c5d4fda7d2e..e080d7037bab71 100644
--- a/packages/block-editor/src/hooks/position.js
+++ b/packages/block-editor/src/hooks/position.js
@@ -199,17 +199,18 @@ export function PositionEdit( props ) {
const allowFixed = hasFixedPositionSupport( blockName );
const allowSticky = hasStickyPositionSupport( blockName );
+ const value = style?.position?.type;
const options = useMemo( () => {
const availableOptions = [ DEFAULT_OPTION ];
- if ( allowSticky ) {
+ if ( allowSticky || value === STICKY_OPTION.value ) {
availableOptions.push( STICKY_OPTION );
}
- if ( allowFixed ) {
+ if ( allowFixed || value === FIXED_OPTION.value ) {
availableOptions.push( FIXED_OPTION );
}
return availableOptions;
- }, [ allowFixed, allowSticky ] );
+ }, [ allowFixed, allowSticky, value ] );
if ( useIsPositionDisabled( props ) ) {
return null;
@@ -238,18 +239,14 @@ export function PositionEdit( props ) {
} );
};
- const value = style?.position?.type;
const selectedOption = value
- ? options.find( ( option ) => option.value === value )
+ ? options.find( ( option ) => option.value === value ) || DEFAULT_OPTION
: DEFAULT_OPTION;
return Platform.select( {
web: (
<>
-
+
Date: Mon, 9 Jan 2023 16:45:36 +1100
Subject: [PATCH 11/13] Try ensuring sticky/fixed blocks always flip the
toolbar position
---
.../use-block-toolbar-popover-props.js | 34 ++++++++++++++-----
packages/block-editor/src/hooks/position.js | 14 +++++++-
2 files changed, 39 insertions(+), 9 deletions(-)
diff --git a/packages/block-editor/src/components/block-tools/use-block-toolbar-popover-props.js b/packages/block-editor/src/components/block-tools/use-block-toolbar-popover-props.js
index 08f71989df9a1c..f99323dd5c80a7 100644
--- a/packages/block-editor/src/components/block-tools/use-block-toolbar-popover-props.js
+++ b/packages/block-editor/src/components/block-tools/use-block-toolbar-popover-props.js
@@ -16,6 +16,7 @@ import {
*/
import { store as blockEditorStore } from '../../store';
import { __unstableUseBlockElement as useBlockElement } from '../block-list/use-block-props/use-block-refs';
+import { hasStickyOrFixedPositionValue } from '../../hooks/position';
const COMMON_PROPS = {
placement: 'top-start',
@@ -48,6 +49,7 @@ const RESTRICTED_HEIGHT_PROPS = {
* @param {Element} selectedBlockElement The outer DOM element of the first selected block.
* @param {Element} scrollContainer The scrollable container for the contentElement.
* @param {number} toolbarHeight The height of the toolbar in pixels.
+ * @param {boolean} isSticky Whether or not the selected block is sticky or fixed.
*
* @return {Object} The popover props used to determine the position of the toolbar.
*/
@@ -55,7 +57,8 @@ function getProps(
contentElement,
selectedBlockElement,
scrollContainer,
- toolbarHeight
+ toolbarHeight,
+ isSticky
) {
if ( ! contentElement || ! selectedBlockElement ) {
return DEFAULT_PROPS;
@@ -83,7 +86,11 @@ function getProps(
const isBlockTallerThanViewport =
blockRect.height > viewportHeight - toolbarHeight;
- if ( hasSpaceForToolbarAbove || isBlockTallerThanViewport ) {
+ // Sticky blocks are treated as if they will never have enough space for the toolbar above.
+ if (
+ ! isSticky &&
+ ( hasSpaceForToolbarAbove || isBlockTallerThanViewport )
+ ) {
return DEFAULT_PROPS;
}
@@ -105,6 +112,19 @@ export default function useBlockToolbarPopoverProps( {
} ) {
const selectedBlockElement = useBlockElement( clientId );
const [ toolbarHeight, setToolbarHeight ] = useState( 0 );
+ const { blockIndex, isSticky } = useSelect(
+ ( select ) => {
+ const { getBlockIndex, getBlockAttributes } =
+ select( blockEditorStore );
+ return {
+ blockIndex: getBlockIndex( clientId ),
+ isSticky: hasStickyOrFixedPositionValue(
+ getBlockAttributes( clientId )
+ ),
+ };
+ },
+ [ clientId ]
+ );
const scrollContainer = useMemo( () => {
if ( ! contentElement ) {
return;
@@ -116,13 +136,10 @@ export default function useBlockToolbarPopoverProps( {
contentElement,
selectedBlockElement,
scrollContainer,
- toolbarHeight
+ toolbarHeight,
+ isSticky
)
);
- const blockIndex = useSelect(
- ( select ) => select( blockEditorStore ).getBlockIndex( clientId ),
- [ clientId ]
- );
const popoverRef = useRefEffect( ( popoverNode ) => {
setToolbarHeight( popoverNode.offsetHeight );
@@ -135,7 +152,8 @@ export default function useBlockToolbarPopoverProps( {
contentElement,
selectedBlockElement,
scrollContainer,
- toolbarHeight
+ toolbarHeight,
+ isSticky
)
),
[ contentElement, selectedBlockElement, scrollContainer, toolbarHeight ]
diff --git a/packages/block-editor/src/hooks/position.js b/packages/block-editor/src/hooks/position.js
index e080d7037bab71..47c063d1fd7d11 100644
--- a/packages/block-editor/src/hooks/position.js
+++ b/packages/block-editor/src/hooks/position.js
@@ -136,12 +136,24 @@ export function hasPositionSupport( blockType ) {
* Checks if there is a current value in the position block support attributes.
*
* @param {Object} props Block props.
- * @return {boolean} Whether or not the block has a position value set.
+ * @return {boolean} Whether or not the block has a position value set.
*/
export function hasPositionValue( props ) {
return props.attributes.style?.position?.type !== undefined;
}
+/**
+ * Checks if the block is currently set to a sticky or fixed position.
+ * This check is helpful for determining how to position block toolbars or other elements.
+ *
+ * @param {Object} attributes Block attributes.
+ * @return {boolean} Whether or not the block is set to a sticky or fixed position.
+ */
+export function hasStickyOrFixedPositionValue( attributes ) {
+ const positionType = attributes.style?.position?.type;
+ return positionType === 'sticky' || positionType === 'fixed';
+}
+
/**
* Resets the position block support attributes. This can be used when disabling
* the position support controls for a block via a `ToolsPanel`.
From 911771ff08901704e73257ae2cf77019fd54b0b0 Mon Sep 17 00:00:00 2001
From: Andrew Serong <14988353+andrewserong@users.noreply.github.com>
Date: Tue, 10 Jan 2023 16:02:20 +1100
Subject: [PATCH 12/13] Ensure position UI and style output is only applied on
themes that support it, tidy up comments
---
lib/block-supports/position.php | 15 +++++++++++-
packages/block-editor/src/hooks/position.js | 27 ++++++++++-----------
2 files changed, 27 insertions(+), 15 deletions(-)
diff --git a/lib/block-supports/position.php b/lib/block-supports/position.php
index a2459274dcb931..31f359cb797624 100644
--- a/lib/block-supports/position.php
+++ b/lib/block-supports/position.php
@@ -43,6 +43,19 @@ function gutenberg_render_position_support( $block_content, $block ) {
return $block_content;
}
+ $global_settings = gutenberg_get_global_settings();
+ $theme_has_sticky_support = _wp_array_get( $global_settings, array( 'position', 'sticky' ), false );
+ $theme_has_fixed_support = _wp_array_get( $global_settings, array( 'position', 'fixed' ), false );
+
+ // Only allow output for position types that the theme supports.
+ $allowed_position_types = array();
+ if ( true === $theme_has_sticky_support ) {
+ $allowed_position_types[] = 'sticky';
+ }
+ if ( true === $theme_has_fixed_support ) {
+ $allowed_position_types[] = 'fixed';
+ }
+
$style_attribute = _wp_array_get( $block, array( 'attrs', 'style' ), null );
$class_name = wp_unique_id( 'wp-container-' );
$selector = ".$class_name";
@@ -50,7 +63,7 @@ function gutenberg_render_position_support( $block_content, $block ) {
$position_type = _wp_array_get( $style_attribute, array( 'position', 'type' ), '' );
if (
- in_array( $position_type, array( 'fixed', 'sticky' ), true )
+ in_array( $position_type, $allowed_position_types, true )
) {
$sides = array( 'top', 'right', 'bottom', 'left' );
diff --git a/packages/block-editor/src/hooks/position.js b/packages/block-editor/src/hooks/position.js
index 47c063d1fd7d11..82fe7654fa541e 100644
--- a/packages/block-editor/src/hooks/position.js
+++ b/packages/block-editor/src/hooks/position.js
@@ -195,8 +195,8 @@ export function useIsPositionDisabled( { name: blockName } = {} ) {
return ! hasPositionSupport( blockName ) || isDisabled;
}
-/**
- * Inspector control panel containing the padding related configuration
+/*
+ * Position controls to be rendered in an inspector control panel.
*
* @param {Object} props
*
@@ -224,10 +224,6 @@ export function PositionEdit( props ) {
return availableOptions;
}, [ allowFixed, allowSticky, value ] );
- if ( useIsPositionDisabled( props ) ) {
- return null;
- }
-
const onChangeType = ( next ) => {
// For now, use a hard-coded `0px` value for the position.
// `0px` is preferred over `0` as it can be used in `calc()` functions.
@@ -286,7 +282,7 @@ export function PositionEdit( props ) {
}
/**
- * Override the default edit UI to include layout controls
+ * Override the default edit UI to include position controls.
*
* @param {Function} BlockEdit Original component.
*
@@ -299,9 +295,11 @@ export const withInspectorControls = createHigherOrderComponent(
blockName,
POSITION_SUPPORT_KEY
);
+ const showPositionControls =
+ positionSupport && ! useIsPositionDisabled( props );
return [
- positionSupport && (
+ showPositionControls && (
- { hasPositionBlockSupport &&
+ { allowPositionStyles &&
element &&
!! css &&
createPortal( , element ) }
From a96933f48e6a3706c95c99168254d82d898015b7 Mon Sep 17 00:00:00 2001
From: Andrew Serong <14988353+andrewserong@users.noreply.github.com>
Date: Tue, 10 Jan 2023 16:18:52 +1100
Subject: [PATCH 13/13] Clarify TODO comment for z-index values
---
lib/block-supports/position.php | 2 +-
packages/block-editor/src/hooks/position.js | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/block-supports/position.php b/lib/block-supports/position.php
index 31f359cb797624..8d1436049a7e42 100644
--- a/lib/block-supports/position.php
+++ b/lib/block-supports/position.php
@@ -102,7 +102,7 @@ function gutenberg_render_position_support( $block_content, $block ) {
'selector' => $selector,
'declarations' => array(
'position' => $position_type,
- 'z-index' => '10', // TODO: This hard-coded value should live somewhere else.
+ 'z-index' => '10', // TODO: Replace hard-coded z-index value with a z-index preset approach in theme.json.
),
);
}
diff --git a/packages/block-editor/src/hooks/position.js b/packages/block-editor/src/hooks/position.js
index 82fe7654fa541e..1e50c35bfd0e6f 100644
--- a/packages/block-editor/src/hooks/position.js
+++ b/packages/block-editor/src/hooks/position.js
@@ -88,7 +88,7 @@ export function getPositionCSS( { selector, style } ) {
} );
if ( positionType === 'sticky' || positionType === 'fixed' ) {
- // TODO: Work out where to put the magic z-index value.
+ // TODO: Replace hard-coded z-index value with a z-index preset approach in theme.json.
output += `z-index: 10`;
}
output += `}`;