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

Format toolbar: visual clue for hidden active items #21892

Merged
merged 1 commit into from
Sep 10, 2021
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
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
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;
}