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

Always show icon in block toolbar #11600

Merged
merged 1 commit into from
Nov 9, 2018
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
15 changes: 14 additions & 1 deletion packages/editor/src/components/block-switcher/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,20 @@ export class BlockSwitcher extends Component {
const hasStyles = blocks.length === 1 && get( blockType, [ 'styles' ], [] ).length !== 0;

if ( ! hasStyles && ! possibleBlockTransformations.length ) {
return null;
if ( blocks.length > 1 ) {
Copy link
Member

@aduth aduth Jan 3, 2019

Choose a reason for hiding this comment

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

Why do we care about whether there's a multi-selection here, when in the rendering of the IconButton below this outer if block, we use blockType.icon (the first selected block's icon) whether or not it's a multi-selection.

Arrived here via rebasing of #12828, where this code is problematic and difficult to resolve due to the inconsistent forking logic.

Copy link
Member

Choose a reason for hiding this comment

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

return null;
}
return (
<Toolbar>
<IconButton
disabled
className="editor-block-switcher__no-switcher-icon"
label={ __( 'Block icon' ) }
>
<BlockIcon icon={ blockType.icon } showColors />
</IconButton>
</Toolbar>
);
}

return (
Expand Down
20 changes: 16 additions & 4 deletions packages/editor/src/components/block-switcher/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,27 @@
height: $icon-button-size;
}

// Style this the same as the block buttons in the library.
// Needs specificiity to override the icon button.
.components-icon-button.editor-block-switcher__toggle {
width: auto;
.components-icon-button.editor-block-switcher__toggle,
.components-icon-button.editor-block-switcher__no-switcher-icon {
margin: 0;
display: block;
height: $icon-button-size;
padding: 3px;
}


.components-icon-button.editor-block-switcher__no-switcher-icon {
width: $icon-button-size + 6px + 6px;
.editor-block-icon {
margin-right: auto;
margin-left: auto;
}
}

// Style this the same as the block buttons in the library.
// Needs specificiity to override the icon button.
.components-icon-button.editor-block-switcher__toggle {
width: auto;
// Unset icon button styles.
&:active,
&:not(:disabled):not([aria-disabled="true"]):hover,
Expand Down