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

Display labels instead of icons in top toolbar. #24304

Merged
merged 29 commits into from Sep 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ed98b65
Add option to show icon labels.
tellthemachines Jul 28, 2020
c297f23
Address review feedback and consolidate
tellthemachines Jul 29, 2020
10f78c5
Move option to general section
tellthemachines Jul 31, 2020
30239dc
Remove unnecessary dispatch
tellthemachines Aug 4, 2020
9201cfe
Display labels instead of icons in top toolbar.
tellthemachines Jul 31, 2020
dcdfbef
Fix dropdown tooltip display
tellthemachines Aug 5, 2020
5e9f459
Adjust button and toolbar styling.
tellthemachines Aug 5, 2020
b4fcdd9
Reposition outline dropdown
tellthemachines Aug 6, 2020
45dc9d1
Try button tertiary styles
tellthemachines Aug 6, 2020
54eede9
Update button styles
tellthemachines Aug 11, 2020
f5fd779
Add translator comments to top toolbar buttons.
tellthemachines Aug 11, 2020
ec49857
Fix failing tests.
tellthemachines Aug 11, 2020
8fbbfea
Update e2e test selector.
tellthemachines Aug 11, 2020
1c52895
Fix translator comments.
tellthemachines Aug 14, 2020
0a8350b
Change header toolbar menu labels.
tellthemachines Aug 25, 2020
02785d4
Change options labels
tellthemachines Aug 25, 2020
fff6bf9
Update snapshot.
tellthemachines Aug 25, 2020
e9cb2f1
Update e2e selector
tellthemachines Aug 25, 2020
82a8afa
Change labels
tellthemachines Aug 26, 2020
b0191bd
Styling tweaks
tellthemachines Aug 26, 2020
9ada627
Try Settings button inside Options dropdown
tellthemachines Aug 26, 2020
e32ad7f
Expand modes in Tools dropdown
tellthemachines Aug 26, 2020
5080c03
Button styling adjustments
tellthemachines Aug 27, 2020
7f6b48c
Fix inserter aria label
tellthemachines Aug 27, 2020
b2d59f6
Fix e2e selector.
tellthemachines Aug 27, 2020
20c3e33
Actually change all the e2e selectors.
tellthemachines Aug 27, 2020
ff2981c
Styling improvements
tellthemachines Aug 28, 2020
84c9811
Fix buttons on small breakpoint.
tellthemachines Aug 28, 2020
52785f0
Address remaining feedback and style fixes.
tellthemachines Aug 28, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -53,7 +53,8 @@ function BlockNavigationDropdownToggle( {
icon={ MenuIcon }
aria-expanded={ isOpen }
onClick={ isEnabled ? onToggle : undefined }
label={ __( 'Block navigation' ) }
/* translators: button label text should, if possible, be under 16 characters. */
label={ __( 'Outline' ) }
className="block-editor-block-navigation"
shortcut={ shortcut }
aria-disabled={ ! isEnabled }
Expand Down
Expand Up @@ -32,6 +32,7 @@ export default function PreviewOptions( {
isTertiary: true,
className: 'block-editor-post-preview__button-toggle',
disabled: ! isEnabled,
/* translators: button label text should, if possible, be under 16 characters. */
children: __( 'Preview' ),
};
return (
Expand Down
5 changes: 3 additions & 2 deletions packages/block-editor/src/components/tool-selector/index.js
Expand Up @@ -45,13 +45,14 @@ function ToolSelector( props, ref ) {
icon={ isNavigationTool ? selectIcon : editIcon }
aria-expanded={ isOpen }
onClick={ onToggle }
label={ __( 'Tools' ) }
/* translators: button label text should, if possible, be under 16 characters. */
label={ __( 'Modes' ) }
/>
) }
position="bottom right"
renderContent={ () => (
<>
<NavigableMenu role="menu" aria-label={ __( 'Tools' ) }>
<NavigableMenu role="menu" aria-label={ __( 'Modes' ) }>
<MenuItemsChoice
value={ isNavigationTool ? 'select' : 'edit' }
onSelect={ onSwitchMode }
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/dropdown-menu/index.js
Expand Up @@ -129,7 +129,7 @@ function DropdownMenu( {
aria-haspopup="true"
aria-expanded={ isOpen }
label={ label }
showTooltip
showTooltip={ !! toggleProps?.showTooltip }
>
{ mergedToggleProps.children }
</Button>
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e-test-utils/src/toggle-more-menu.js
Expand Up @@ -3,6 +3,6 @@
*/
export async function toggleMoreMenu() {
await expect( page ).toClick(
'.edit-post-more-menu [aria-label="More tools & options"]'
'.edit-post-more-menu [aria-label="Options"]'
);
}
2 changes: 1 addition & 1 deletion packages/e2e-tests/specs/editor/blocks/columns.test.js
Expand Up @@ -18,7 +18,7 @@ describe( 'Columns', () => {
await insertBlock( 'Columns' );
await closeGlobalBlockInserter();
await page.click( '[aria-label="Two columns; equal split"]' );
await page.click( '[aria-label="Block navigation"]' );
await page.click( '[aria-label="Outline"]' );
const columnBlockMenuItem = (
await page.$x(
'//button[contains(concat(" ", @class, " "), " block-editor-block-navigation-block-select-button ")][text()="Column"]'
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e-tests/specs/editor/blocks/cover.test.js
Expand Up @@ -24,7 +24,7 @@ describe( 'Cover', () => {
);

// Select the cover block.By default the child paragraph gets selected.
await page.click( 'button[aria-label="Block navigation"]' );
await page.click( 'button[aria-label="Outline"]' );
await page.click(
'.block-editor-block-navigation-block__contents-container button'
);
Expand Down
Expand Up @@ -35,7 +35,7 @@ describe( 'Navigating the block hierarchy', () => {
await page.keyboard.type( 'First column' );

// Navigate to the columns blocks.
await page.click( '[aria-label="Block navigation"]' );
await page.click( '[aria-label="Outline"]' );
const columnsBlockMenuItem = (
await page.$x(
"//button[contains(@class,'block-editor-block-navigation-block-select-button') and contains(text(), 'Columns')]"
Expand All @@ -54,7 +54,7 @@ describe( 'Navigating the block hierarchy', () => {
await page.keyboard.type( '3' );

// Navigate to the last column block.
await page.click( '[aria-label="Block navigation"]' );
await page.click( '[aria-label="Outline"]' );
const lastColumnsBlockMenuItem = (
await page.$x(
"//button[contains(@class,'block-editor-block-navigation-block-select-button') and contains(text(), 'Column')]"
Expand Down Expand Up @@ -159,8 +159,8 @@ describe( 'Navigating the block hierarchy', () => {
// Unselect the blocks
await page.click( '.editor-post-title' );

// Try selecting the group block using the block navigation
await page.click( '[aria-label="Block navigation"]' );
// Try selecting the group block using the Outline
await page.click( '[aria-label="Outline"]' );
const groupMenuItem = (
await page.$x(
"//button[contains(@class,'block-editor-block-navigation-block-select-button') and contains(text(), 'Group')]"
Expand Down
5 changes: 2 additions & 3 deletions packages/e2e-tests/specs/editor/various/dropdown-menu.test.js
Expand Up @@ -3,10 +3,9 @@
*/
import { createNewPost, pressKeyTimes } from '@wordpress/e2e-test-utils';

const moreMenuButtonSelector =
'.components-button[aria-label="More tools & options"]';
const moreMenuButtonSelector = '.components-button[aria-label="Options"]';
const moreMenuDropdownSelector =
'.components-dropdown-menu__menu[aria-label="More tools & options"]';
'.components-dropdown-menu__menu[aria-label="Options"]';
const menuItemsSelector = [ 'menuitem', 'menuitemcheckbox', 'menuitemradio' ]
.map( ( role ) => `${ moreMenuDropdownSelector } [role="${ role }"]` )
.join( ',' );
Expand Down
Expand Up @@ -12,7 +12,7 @@ import { __ } from '@wordpress/i18n';
import { addQueryArgs } from '@wordpress/url';
import { wordpress } from '@wordpress/icons';

function FullscreenModeClose() {
function FullscreenModeClose( { showTooltip } ) {
const { isActive, isRequestingSiteIcon, postType, siteIconUrl } = useSelect(
( select ) => {
const { getCurrentPostType } = select( 'core/editor' );
Expand Down Expand Up @@ -61,7 +61,7 @@ function FullscreenModeClose() {
post_type: postType.slug,
} ) }
label={ get( postType, [ 'labels', 'view_items' ], __( 'Back' ) ) }
showTooltip
showTooltip={ showTooltip }
>
{ buttonIcon }
</Button>
Expand Down
128 changes: 111 additions & 17 deletions packages/edit-post/src/components/header/header-toolbar/index.js
Expand Up @@ -15,7 +15,13 @@ import {
EditorHistoryRedo,
EditorHistoryUndo,
} from '@wordpress/editor';
import { Button, ToolbarItem } from '@wordpress/components';
import {
Button,
DropdownMenu,
ToolbarItem,
MenuItemsChoice,
MenuGroup,
} from '@wordpress/components';
import { plus } from '@wordpress/icons';
import { useRef } from '@wordpress/element';

Expand All @@ -28,6 +34,8 @@ function HeaderToolbar() {
isInserterOpened,
isTextModeEnabled,
previewDeviceType,
showIconLabels,
isNavigationTool,
} = useSelect( ( select ) => {
const {
hasInserterItems,
Expand All @@ -52,9 +60,15 @@ function HeaderToolbar() {
previewDeviceType: select(
'core/edit-post'
).__experimentalGetPreviewDeviceType(),
showIconLabels: select( 'core/edit-post' ).isFeatureActive(
'showIconLabels'
),
isNavigationTool: select( 'core/block-editor' ).isNavigationMode(),
};
}, [] );
const isLargeViewport = useViewportMatch( 'medium' );
const isWideViewport = useViewportMatch( 'wide' );
const isSmallViewport = useViewportMatch( 'small', '<' );

const displayBlockToolbar =
! isLargeViewport || previewDeviceType !== 'Desktop' || hasFixedToolbar;
Expand All @@ -65,6 +79,30 @@ function HeaderToolbar() {
: /* translators: accessibility text for the editor toolbar when Top Toolbar is off */
__( 'Document tools' );

const { setNavigationMode } = useDispatch( 'core/block-editor' );

const onSwitchMode = ( mode ) => {
setNavigationMode( mode === 'edit' ? false : true );
};

const overflowItems = (
<>
<ToolbarItem
as={ TableOfContents }
hasOutlineItemsDisabled={ isTextModeEnabled }
repositionDropdown={ showIconLabels && ! isWideViewport }
showTooltip={ ! showIconLabels }
isTertiary={ showIconLabels }
/>
<ToolbarItem
as={ BlockNavigationDropdown }
isDisabled={ isTextModeEnabled }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The disabled items in the overflow menu don't seem to be consistent with other dropdown menus:
Screenshot 2020-08-13 at 4 01 11 pm

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, they are meant to be consistent with their out-of-overflow state 😅 but perhaps @mapk can comment further on that.

showTooltip={ ! showIconLabels }
isTertiary={ showIconLabels }
/>
</>
);

return (
<NavigableToolbar
className="edit-post-header-toolbar"
Expand All @@ -89,27 +127,83 @@ function HeaderToolbar() {
} }
disabled={ ! isInserterEnabled }
icon={ plus }
/* translators: button label text should, if possible, be under 16
characters. */
label={ _x(
'Add block',
'Generic label for block inserter button'
) }
/>
{ isLargeViewport && (
<ToolbarItem
as={ ToolSelector }
disabled={ isTextModeEnabled }
/>
showTooltip={ ! showIconLabels }
>
{ showIconLabels && __( 'Add' ) }
</ToolbarItem>
{ ( isWideViewport || ! showIconLabels ) && (
<>
{ isLargeViewport && (
<ToolbarItem
as={ ToolSelector }
showTooltip={ ! showIconLabels }
isTertiary={ showIconLabels }
disabled={ isTextModeEnabled }
/>
) }
<ToolbarItem
as={ EditorHistoryUndo }
showTooltip={ ! showIconLabels }
isTertiary={ showIconLabels }
/>
<ToolbarItem
as={ EditorHistoryRedo }
showTooltip={ ! showIconLabels }
isTertiary={ showIconLabels }
/>
{ overflowItems }
</>
) }
{ ! isWideViewport && ! isSmallViewport && showIconLabels && (
<DropdownMenu
position="bottom right"
label={
/* translators: button label text should, if possible, be under 16
characters. */
__( 'Tools' )
}
>
{ () => (
<div className="edit-post-header__dropdown">
<MenuGroup label={ __( 'Modes' ) }>
<MenuItemsChoice
value={
isNavigationTool ? 'select' : 'edit'
}
onSelect={ onSwitchMode }
choices={ [
{
value: 'edit',
label: __( 'Edit' ),
},
{
value: 'select',
label: __( 'Select' ),
},
] }
/>
</MenuGroup>
<MenuGroup label={ __( 'Edit' ) }>
<EditorHistoryUndo
showTooltip={ ! showIconLabels }
isTertiary={ showIconLabels }
/>
<EditorHistoryRedo
showTooltip={ ! showIconLabels }
isTertiary={ showIconLabels }
/>
</MenuGroup>
<MenuGroup>{ overflowItems }</MenuGroup>
</div>
) }
</DropdownMenu>
) }
<ToolbarItem as={ EditorHistoryUndo } />
<ToolbarItem as={ EditorHistoryRedo } />
<ToolbarItem
as={ TableOfContents }
hasOutlineItemsDisabled={ isTextModeEnabled }
/>
<ToolbarItem
as={ BlockNavigationDropdown }
isDisabled={ isTextModeEnabled }
/>
{ displayBlockToolbar && (
<div className="edit-post-header-toolbar__block-toolbar">
<BlockToolbar hideDragHandle />
Expand Down
24 changes: 24 additions & 0 deletions packages/edit-post/src/components/header/header-toolbar/style.scss
Expand Up @@ -113,3 +113,27 @@
height: 32px;
padding: 0;
}

.show-icon-labels {
// Always display block toolbar under main toolbar when text labels are visible
.edit-post-header-toolbar__block-toolbar {
@include break-wide {
position: absolute;
top: $header-height + $border-width;
left: 0;
right: 0;
border-bottom: $border-width solid $gray-200;
padding: 0;
background-color: $white;

.block-editor-block-toolbar .components-toolbar-group,
.block-editor-block-toolbar .components-toolbar {
height: auto;
padding: 0;
}
}
}
.edit-post-header-toolbar__inserter-toggle.edit-post-header-toolbar__inserter-toggle.edit-post-header-toolbar__inserter-toggle {
height: 36px;
}
}
25 changes: 22 additions & 3 deletions packages/edit-post/src/components/header/index.js
Expand Up @@ -7,6 +7,7 @@ import {
PinnedItems,
__experimentalMainDashboardButton as MainDashboardButton,
} from '@wordpress/interface';
import { useViewportMatch } from '@wordpress/compose';

/**
* Internal dependencies
Expand All @@ -18,17 +19,27 @@ import PostPublishButtonOrToggle from './post-publish-button-or-toggle';
import { default as DevicePreview } from '../device-preview';

function Header( { setEntitiesSavedStatesCallback } ) {
const { hasActiveMetaboxes, isPublishSidebarOpened, isSaving } = useSelect(
const {
hasActiveMetaboxes,
isPublishSidebarOpened,
isSaving,
showIconLabels,
} = useSelect(
( select ) => ( {
hasActiveMetaboxes: select( 'core/edit-post' ).hasMetaBoxes(),
isPublishSidebarOpened: select(
'core/edit-post'
).isPublishSidebarOpened(),
isSaving: select( 'core/edit-post' ).isSavingMetaBoxes(),
showIconLabels: select( 'core/edit-post' ).isFeatureActive(
'showIconLabels'
),
} ),
[]
);

const isLargeViewport = useViewportMatch( 'large' );

return (
<div className="edit-post-header">
<MainDashboardButton.Slot>
Expand All @@ -47,6 +58,7 @@ function Header( { setEntitiesSavedStatesCallback } ) {
<PostSavedState
forceIsDirty={ hasActiveMetaboxes }
forceIsSaving={ isSaving }
showIconLabels={ showIconLabels }
/>
) }
<DevicePreview />
Expand All @@ -61,8 +73,15 @@ function Header( { setEntitiesSavedStatesCallback } ) {
setEntitiesSavedStatesCallback
}
/>
<PinnedItems.Slot scope="core/edit-post" />
<MoreMenu />
{ ( isLargeViewport || ! showIconLabels ) && (
<>
<PinnedItems.Slot scope="core/edit-post" />
<MoreMenu showIconLabels={ showIconLabels } />
</>
) }
{ showIconLabels && ! isLargeViewport && (
<MoreMenu showIconLabels={ showIconLabels } />
) }
</div>
</div>
);
Expand Down