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

Fix close button position on inserter #61463

Closed
wants to merge 3 commits into from
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 @@ -24,6 +24,7 @@ function InserterLibrary(
__experimentalOnPatternCategorySelection,
onSelect = noop,
shouldFocusBlock = false,
onClose,
},
ref
) {
Expand All @@ -41,6 +42,7 @@ function InserterLibrary(

return (
<InserterMenu
onClose={ onClose }
onSelect={ onSelect }
rootClientId={ destinationRootClientId }
clientId={ clientId }
Expand Down
7 changes: 6 additions & 1 deletion packages/block-editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function InserterMenu(
clientId,
isAppender,
__experimentalInsertionIndex,
onClose,
onSelect,
showInserterHelpPanel,
showMostUsedBlocks,
Expand Down Expand Up @@ -293,7 +294,11 @@ function InserterMenu(
ref={ ref }
>
<div className="block-editor-inserter__main-area">
<InserterTabs ref={ tabsRef } onSelect={ handleSetSelectedTab }>
<InserterTabs
ref={ tabsRef }
onClose={ onClose }
onSelect={ handleSetSelectedTab }
>
{ inserterSearch }
{ selectedTab === 'blocks' &&
! delayedFilterValue &&
Expand Down
39 changes: 26 additions & 13 deletions packages/block-editor/src/components/inserter/tabs.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
/**
* WordPress dependencies
*/
import { privateApis as componentsPrivateApis } from '@wordpress/components';
import {
Button,
privateApis as componentsPrivateApis,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { forwardRef } from '@wordpress/element';
import { closeSmall } from '@wordpress/icons';

/**
* Internal dependencies
Expand All @@ -29,23 +33,32 @@ const mediaTab = {
title: __( 'Media' ),
};

function InserterTabs( { onSelect, children }, ref ) {
function InserterTabs( { onClose, onSelect, children }, ref ) {
const tabs = [ blocksTab, patternsTab, mediaTab ];

return (
<div className="block-editor-inserter__tabs" ref={ ref }>
<Tabs onSelect={ onSelect }>
<Tabs.TabList className="block-editor-inserter__tablist">
{ tabs.map( ( tab ) => (
<Tabs.Tab
key={ tab.name }
tabId={ tab.name }
className="block-editor-inserter__tab"
>
{ tab.title }
</Tabs.Tab>
) ) }
</Tabs.TabList>
<div className="block-editor-inserter-sidebar__header">
<Button
className="editor-inserter-sidebar__close-button"
icon={ closeSmall }
label={ __( 'Close block inserter' ) }
onClick={ () => onClose() }
size="small"
/>
<Tabs.TabList className="block-editor-inserter__tablist">
{ tabs.map( ( tab ) => (
<Tabs.Tab
key={ tab.name }
tabId={ tab.name }
className="block-editor-inserter__tab"
>
{ tab.title }
</Tabs.Tab>
) ) }
</Tabs.TabList>
</div>
{ tabs.map( ( tab ) => (
<Tabs.TabPanel
key={ tab.name }
Expand Down
15 changes: 2 additions & 13 deletions packages/editor/src/components/inserter-sidebar/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
/**
* WordPress dependencies
*/
import { useDispatch, useSelect } from '@wordpress/data';
import { Button } from '@wordpress/components';
import { __experimentalLibrary as Library } from '@wordpress/block-editor';
import { closeSmall } from '@wordpress/icons';
import { useDispatch, useSelect } from '@wordpress/data';
import {
useViewportMatch,
__experimentalUseDialog as useDialog,
} from '@wordpress/compose';
import { __ } from '@wordpress/i18n';
import { useRef } from '@wordpress/element';
import { store as preferencesStore } from '@wordpress/preferences';

Expand Down Expand Up @@ -47,15 +44,6 @@ export default function InserterSidebar( {
{ ...inserterDialogProps }
className="editor-inserter-sidebar"
>
<div className="editor-inserter-sidebar__header">
<Button
className="editor-inserter-sidebar__close-button"
icon={ closeSmall }
label={ __( 'Close block inserter' ) }
onClick={ () => setIsInserterOpened( false ) }
size="small"
/>
</div>
<div className="editor-inserter-sidebar__content">
<Library
showMostUsedBlocks={ showMostUsedBlocks }
Expand All @@ -69,6 +57,7 @@ export default function InserterSidebar( {
__experimentalOnPatternCategorySelection={
isRightSidebarOpen ? closeGeneralSidebar : undefined
}
onClose={ () => setIsInserterOpened( false ) }
ref={ libraryRef }
/>
</div>
Expand Down
10 changes: 9 additions & 1 deletion packages/editor/src/components/inserter-sidebar/style.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// This width comes from the Inserter component in the block editor package.
$block-inserter-width: 350px;

.editor-inserter-sidebar {
@include reset;

Expand All @@ -7,10 +10,15 @@
}

.editor-inserter-sidebar__header {
border-bottom: $border-width solid $gray-300;
position: relative;
display: flex;
justify-content: flex-end;
justify-content: space-between;
z-index: z-index(".editor-inserter-sidebar__header");
.editor-inserter-sidebar__close-button {
order: 1;
align-self: center;
}
}

.editor-inserter-sidebar__close-button {
Expand Down
Loading