Skip to content

Commit

Permalink
Format toolbar: visual clue for hidden active items
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Sep 10, 2021
1 parent 435119c commit 82cb606
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ exports[`AlignmentUI should allow custom alignment controls to be specified 1`]
}
toggleProps={
Object {
"className": "is-pressed",
"describedBy": "Change text alignment",
}
}
Expand Down Expand Up @@ -133,6 +134,7 @@ exports[`AlignmentUI should match snapshot 1`] = `
}
toggleProps={
Object {
"className": "is-pressed",
"describedBy": "Change text alignment",
}
}
Expand Down
5 changes: 4 additions & 1 deletion packages/block-editor/src/components/alignment-control/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ function AlignmentUI( {
<UIComponent
icon={ setIcon() }
label={ label }
toggleProps={ { describedBy } }
toggleProps={ {
describedBy,
className: activeAlignment ? 'is-pressed' : undefined,
} }
popoverProps={ POPOVER_PROPS }
controls={ alignmentControls.map( ( control ) => {
const { align } = control;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ exports[`BlockAlignmentUI should match snapshot 1`] = `
}
toggleProps={
Object {
"className": "is-pressed",
"describedBy": "Change alignment",
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ function BlockAlignmentUI( {

const UIComponent = isToolbar ? ToolbarGroup : ToolbarDropdownMenu;
const extraProps = isToolbar ? { isCollapsed } : {};
const hasActive = enabledControls.some( ( control ) => control === value );

return (
<UIComponent
Expand All @@ -77,7 +78,10 @@ function BlockAlignmentUI( {
: defaultAlignmentControl.icon
}
label={ __( 'Align' ) }
toggleProps={ { describedBy: __( 'Change alignment' ) } }
toggleProps={ {
describedBy: __( 'Change alignment' ),
className: hasActive ? 'is-pressed' : undefined,
} }
controls={ enabledControls.map( ( control ) => {
return {
...BLOCK_ALIGNMENTS_CONTROLS[ control ],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

import { orderBy } from 'lodash';
import classnames from 'classnames';

/**
* WordPress dependencies
Expand All @@ -20,22 +21,37 @@ const POPOVER_PROPS = {
const FormatToolbar = () => {
return (
<>
{ [ 'bold', 'italic', 'link', 'text-color' ].map( ( format ) => (
{ [ 'bold', 'italic', 'link' ].map( ( format ) => (
<Slot
name={ `RichText.ToolbarControls.${ format }` }
key={ format }
/>
) ) }
<Slot name="RichText.ToolbarControls">
{ ( fills ) =>
fills.length !== 0 && (
{ ( fills ) => {
if ( ! fills.length ) {
return null;
}

const allProps = fills.map( ( [ { props } ] ) => props );
const hasActive = allProps.some(
( { isActive } ) => isActive
);

return (
<ToolbarItem>
{ ( toggleProps ) => (
<DropdownMenu
icon={ chevronDown }
/* translators: button label text should, if possible, be under 16 characters. */
label={ __( 'More' ) }
toggleProps={ toggleProps }
toggleProps={ {
...toggleProps,
className: classnames(
toggleProps.className,
{ 'is-pressed': hasActive }
),
} }
controls={ orderBy(
fills.map( ( [ { props } ] ) => props ),
'title'
Expand All @@ -44,8 +60,8 @@ const FormatToolbar = () => {
/>
) }
</ToolbarItem>
)
}
);
} }
</Slot>
</>
);
Expand Down
3 changes: 1 addition & 2 deletions packages/format-library/src/text-color/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ function TextColorEdit( {
return (
<>
<RichTextToolbarButton
key={ isActive ? 'text-color' : 'text-color-not-active' }
className="format-library-text-color-button"
name={ isActive ? 'text-color' : undefined }
isActive={ isActive }
icon={
<>
<Icon icon={ textColorIcon } />
Expand Down
4 changes: 2 additions & 2 deletions packages/format-library/src/text-color/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@
height: 4px;
width: 20px;
position: absolute;
bottom: 10px;
left: 8px;
bottom: 13px;
left: 16px;
}

0 comments on commit 82cb606

Please sign in to comment.