Skip to content
Merged
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
33 changes: 32 additions & 1 deletion packages/block-editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
forwardRef,
useState,
useCallback,
useEffect,
useMemo,
useRef,
useLayoutEffect,
Expand Down Expand Up @@ -168,6 +169,30 @@ function InserterMenu(

const showMediaPanel = selectedTab === 'media' && !! selectedMediaCategory;

const [ isScrolled, setIsScrolled ] = useState( false );
const blocksPanelRef = useRef( null );
const patternsPanelRef = useRef( null );
const mediaPanelRef = useRef( null );
useEffect( () => {
const handleScroll = ( event ) => {
setIsScrolled( event.currentTarget.scrollTop > 0 );
};
const panels = [
blocksPanelRef.current,
patternsPanelRef.current,
mediaPanelRef.current,
].filter( Boolean );
panels.forEach( ( panel ) =>
panel.addEventListener( 'scroll', handleScroll )
);

return () => {
panels.forEach( ( panel ) =>
panel.removeEventListener( 'scroll', handleScroll )
);
};
}, [] );

const inserterSearch = useMemo( () => {
if ( selectedTab === 'media' ) {
return null;
Expand All @@ -176,7 +201,9 @@ function InserterMenu(
return (
<>
<SearchControl
className="block-editor-inserter__search"
className={ clsx( 'block-editor-inserter__search', {
'is-scrolled': isScrolled,
} ) }
onChange={ ( value ) => {
if ( hoveredItem ) {
setHoveredItem( null );
Expand Down Expand Up @@ -219,6 +246,7 @@ function InserterMenu(
rootClientId,
__experimentalInsertionIndex,
isAppender,
isScrolled,
] );

const blocksTab = useMemo( () => {
Expand Down Expand Up @@ -343,6 +371,7 @@ function InserterMenu(
{
name: 'blocks',
title: __( 'Blocks' ),
panelRef: blocksPanelRef,
panel: (
<>
{ inserterSearch }
Expand All @@ -355,6 +384,7 @@ function InserterMenu(
{
name: 'patterns',
title: __( 'Patterns' ),
panelRef: patternsPanelRef,
panel: (
<>
{ inserterSearch }
Expand All @@ -367,6 +397,7 @@ function InserterMenu(
{
name: 'media',
title: __( 'Media' ),
panelRef: mediaPanelRef,
panel: (
<>
{ inserterSearch }
Expand Down
21 changes: 18 additions & 3 deletions packages/block-editor/src/components/inserter/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,18 @@ $block-inserter-tabs-height: 44px;
}

.block-editor-inserter__search {
padding: $grid-unit-20 $grid-unit-20 0 $grid-unit-20;
padding: $grid-unit-20;
position: sticky;
top: 0;
z-index: 2;
background-color: $white;
border-bottom: 1px solid transparent;
@media not ( prefers-reduced-motion ) {
transition: border-bottom-color 0.1s linear;
}
&.is-scrolled {
border-bottom-color: $gray-200;
}
}

.block-editor-inserter__no-tab-container {
Expand All @@ -138,7 +149,7 @@ $block-inserter-tabs-height: 44px;

display: inline-flex;
align-items: center;
padding: $grid-unit-20 $grid-unit-20 0;
padding: 0 $grid-unit-20;
}

.block-editor-inserter__panel-content {
Expand Down Expand Up @@ -224,12 +235,16 @@ $block-inserter-tabs-height: 44px;
.block-editor-inserter__media-tabs-container,
.block-editor-inserter__block-patterns-tabs-container {
flex-grow: 1;
padding: $grid-unit-20;
padding: 0 $grid-unit-20 $grid-unit-20;
display: flex;
flex-direction: column;
justify-content: space-between;
}

.block-editor-inserter__media-tabs-container {
padding-top: $grid-unit-20;
}

.block-editor-inserter__category-tablist {
margin-bottom: $grid-unit-10;
}
Expand Down
Loading