Skip to content
Closed
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions packages/base-styles/_z-index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ $z-layers: (
// Appear under the customizer heading UI, but over anything else.
".customize-widgets__topbar": 8,

// Appear under the topbar.
".customize-widgets__block-toolbar": 7,
// Appear over the topbar of both editor and customizer.
".customize-widgets__block-toolbar": 10,
);

@function z-index( $key ) {
Expand Down
1 change: 1 addition & 0 deletions packages/block-editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ _Parameters_
- _$0_ `Object`: Props.
- _$0.children_ `Object`: The block content and style container.
- _$0.\_\_unstableContentRef_ `Object`: Ref holding the content scroll container.
- _$0.\_\_experimentalStickyTop_ `Object`: Offset for the top position of toolbars.

<a name="BlockVerticalAlignmentControl" href="#BlockVerticalAlignmentControl">#</a> **BlockVerticalAlignmentControl**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ import NavigableToolbar from '../navigable-toolbar';
import BlockToolbar from '../block-toolbar';
import { store as blockEditorStore } from '../../store';

function BlockContextualToolbar( { focusOnMount, isFixed, ...props } ) {
function BlockContextualToolbar( {
focusOnMount,
isFixed,
__experimentalStickyTop,
style = {},
...props
} ) {
const { blockType, hasParents, showParentSelector } = useSelect(
( select ) => {
const {
Expand Down Expand Up @@ -59,12 +65,17 @@ function BlockContextualToolbar( { focusOnMount, isFixed, ...props } ) {
'is-fixed': isFixed,
} );

if ( __experimentalStickyTop ) {
style.top = __experimentalStickyTop;
}

return (
<NavigableToolbar
focusOnMount={ focusOnMount }
className={ classes }
/* translators: accessibility text for the block toolbar */
aria-label={ __( 'Block tools' ) }
style={ style }
{ ...props }
>
<BlockToolbar hideDragHandle={ isFixed } />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function BlockPopover( {
capturingClientId,
__unstablePopoverSlot,
__unstableContentRef,
__experimentalStickyTop,
} ) {
const {
isNavigationMode,
Expand Down Expand Up @@ -213,6 +214,7 @@ function BlockPopover( {
// Observe movement for block animations (especially horizontal).
__unstableObserveElement={ node }
shouldAnchorIncludePadding
__experimentalStickyTop={ __experimentalStickyTop }
>
{ ( shouldShowContextualToolbar || isToolbarForced ) && (
<div
Expand Down Expand Up @@ -324,6 +326,7 @@ function wrapperSelector( select ) {
export default function WrappedBlockPopover( {
__unstablePopoverSlot,
__unstableContentRef,
__experimentalStickyTop,
} ) {
const selected = useSelect( wrapperSelector, [] );

Expand Down Expand Up @@ -353,6 +356,7 @@ export default function WrappedBlockPopover( {
capturingClientId={ capturingClientId }
__unstablePopoverSlot={ __unstablePopoverSlot }
__unstableContentRef={ __unstableContentRef }
__experimentalStickyTop={ __experimentalStickyTop }
/>
);
}
23 changes: 17 additions & 6 deletions packages/block-editor/src/components/block-tools/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ import { usePopoverScroll } from './use-popover-scroll';
* insertion point and a slot for the inline rich text toolbar). Must be wrapped
* around the block content and editor styles wrapper or iframe.
*
* @param {Object} $0 Props.
* @param {Object} $0.children The block content and style container.
* @param {Object} $0.__unstableContentRef Ref holding the content scroll container.
* @param {Object} $0 Props.
* @param {Object} $0.children The block content and style container.
* @param {Object} $0.__unstableContentRef Ref holding the content scroll container.
* @param {Object} $0.__experimentalStickyTop Offset for the top position of toolbars.
*/
export default function BlockTools( { children, __unstableContentRef } ) {
export default function BlockTools( {
children,
__unstableContentRef,
__experimentalStickyTop,
} ) {
const isLargeViewport = useViewportMatch( 'medium' );
const hasFixedToolbar = useSelect(
( select ) => select( blockEditorStore ).getSettings().hasFixedToolbar,
Expand All @@ -33,11 +38,17 @@ export default function BlockTools( { children, __unstableContentRef } ) {
return (
<InsertionPoint __unstableContentRef={ __unstableContentRef }>
{ ( hasFixedToolbar || ! isLargeViewport ) && (
<BlockContextualToolbar isFixed />
<BlockContextualToolbar
isFixed
__experimentalStickyTop={ __experimentalStickyTop }
/>
) }
{ /* Even if the toolbar is fixed, the block popover is still
needed for navigation mode. */ }
<BlockPopover __unstableContentRef={ __unstableContentRef } />
<BlockPopover
__unstableContentRef={ __unstableContentRef }
__experimentalStickyTop={ __experimentalStickyTop }
/>
{ /* Used for the inline rich text toolbar. */ }
<Popover.Slot
name="block-toolbar"
Expand Down
6 changes: 4 additions & 2 deletions packages/components/src/popover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ const Popover = (
__unstableBoundaryParent,
__unstableForcePosition,
__unstableForceXAlignment,
__experimentalStickyTop: stickyTop = 0,
/* eslint-enable no-unused-vars */
...contentProps
},
Expand Down Expand Up @@ -305,7 +306,7 @@ const Popover = (

const { offsetParent, ownerDocument } = containerRef.current;

let relativeOffsetTop = 0;
let relativeOffsetTop = -stickyTop;

// If there is a positioned ancestor element that is not the body,
// subtract the position from the anchor rect. If the position of
Expand All @@ -315,7 +316,7 @@ const Popover = (
if ( offsetParent && offsetParent !== ownerDocument.body ) {
const offsetParentRect = offsetParent.getBoundingClientRect();

relativeOffsetTop = offsetParentRect.top;
relativeOffsetTop += offsetParentRect.top;
anchor = new window.DOMRect(
anchor.left - offsetParentRect.left,
anchor.top - offsetParentRect.top,
Expand Down Expand Up @@ -476,6 +477,7 @@ const Popover = (
position,
contentSize,
__unstableStickyBoundaryElement,
stickyTop,
__unstableObserveElement,
__unstableBoundaryParent,
] );
Expand Down
3 changes: 3 additions & 0 deletions packages/customize-widgets/src/components/header/style.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
.customize-widgets-header {
position: sticky;
top: 0;

@include break-medium() {
// Make space for the floating toolbar.
margin-bottom: $grid-unit-60 + $default-block-margin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ import { store as customizeWidgetsStore } from '../../store';
import WelcomeGuide from '../welcome-guide';
import KeyboardShortcuts from '../keyboard-shortcuts';

// Used to offset the block toolbar’s sticky top
const headerHeight = 49;

export default function SidebarBlockEditor( {
blockEditorSettings,
sidebar,
Expand Down Expand Up @@ -113,7 +116,7 @@ export default function SidebarBlockEditor( {
isFixedToolbarActive={ isFixedToolbarActive }
/>

<BlockTools>
<BlockTools __experimentalStickyTop={ headerHeight }>
<BlockSelectionClearer>
<WritingFlow>
<ObserveTyping>
Expand Down
4 changes: 2 additions & 2 deletions packages/customize-widgets/src/controls/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
// Override the inline styles added via JS that make the section title
// sticky feature work. The customize widget block-editor disables this
// sticky title.
padding-top: 10px !important;
padding-top: 12px !important;

.customize-section-title {
// Disable the sticky title. `!important` as this overrides inline
// styles added via JavaScript.
position: static !important;
top: 0 !important;
width: unset !important;
margin-top: -12px !important;
}
}