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

Add ability to hide/disable the search box in the global block inserter #34656

Closed
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
2 changes: 2 additions & 0 deletions packages/block-editor/src/components/inserter/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function InserterLibrary( {
__experimentalInsertionIndex,
onSelect = noop,
shouldFocusBlock = false,
showSearch = true,
} ) {
const destinationRootClientId = useSelect(
( select ) => {
Expand All @@ -45,6 +46,7 @@ function InserterLibrary( {
showMostUsedBlocks={ showMostUsedBlocks }
__experimentalInsertionIndex={ __experimentalInsertionIndex }
shouldFocusBlock={ shouldFocusBlock }
showSearch={ showSearch }
/>
);
}
Expand Down
34 changes: 23 additions & 11 deletions packages/block-editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ import useInsertionPoint from './hooks/use-insertion-point';
import InserterTabs from './tabs';
import { store as blockEditorStore } from '../../store';

/**
* External dependencies
*/
import classnames from 'classnames';

function InserterMenu( {
rootClientId,
clientId,
Expand All @@ -28,6 +33,7 @@ function InserterMenu( {
showInserterHelpPanel,
showMostUsedBlocks,
shouldFocusBlock = true,
showSearch = true,
} ) {
const [ filterValue, setFilterValue ] = useState( '' );
const [ hoveredItem, setHoveredItem ] = useState( null );
Expand Down Expand Up @@ -165,21 +171,27 @@ function InserterMenu( {
[ blocksTab, patternsTab, reusableBlocksTab ]
);

const classes = classnames( 'block-editor-inserter__menu', {
'has-search': !! showSearch,
} );

return (
<div className="block-editor-inserter__menu">
<div className={ classes }>
<div className="block-editor-inserter__main-area">
{ /* the following div is necessary to fix the sticky position of the search form */ }
<div className="block-editor-inserter__content">
<SearchControl
className="block-editor-inserter__search"
onChange={ ( value ) => {
if ( hoveredItem ) setHoveredItem( null );
setFilterValue( value );
} }
value={ filterValue }
label={ __( 'Search for blocks and patterns' ) }
placeholder={ __( 'Search' ) }
/>
{ showSearch && (
<SearchControl
className="block-editor-inserter__search"
onChange={ ( value ) => {
if ( hoveredItem ) setHoveredItem( null );
setFilterValue( value );
} }
value={ filterValue }
label={ __( 'Search for blocks and patterns' ) }
placeholder={ __( 'Search' ) }
/>
) }
{ !! filterValue && (
<InserterSearchResults
filterValue={ filterValue }
Expand Down
8 changes: 6 additions & 2 deletions packages/block-editor/src/components/inserter/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ $block-inserter-tabs-height: 44px;

.components-tab-panel__tabs {
position: sticky;
// Computed based off the search input height and paddings
top: $grid-unit-10 + $grid-unit-20 + $grid-unit-60;
top: 0;
background: $white;
z-index: z-index(".block-editor-inserter__tabs .components-tab-panel__tabs");
border-bottom: $border-width solid $gray-300;
Expand All @@ -139,6 +138,11 @@ $block-inserter-tabs-height: 44px;
}
}

.block-editor-inserter__menu.has-search .block-editor-inserter__tabs .components-tab-panel__tabs {
// Computed based off the search input height and paddings
top: $grid-unit-10 + $grid-unit-20 + $grid-unit-60;
}

.block-editor-inserter__panel-header {
display: inline-flex;
align-items: center;
Expand Down