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

Show duplicative heading level text when showIconLabels is enabled #68804

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
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 @@ -3,6 +3,8 @@
*/
import { ToolbarDropdownMenu } from '@wordpress/components';
import { __, sprintf } from '@wordpress/i18n';
import { store as preferencesStore } from '@wordpress/preferences';
import { useSelect } from '@wordpress/data';

/**
* Internal dependencies
Expand Down Expand Up @@ -46,23 +48,31 @@ export default function HeadingLevelDropdown( {
)
.sort( ( a, b ) => a - b ); // Sorts numerically in ascending order;

const showIconLabels = useSelect(
( select ) =>
select( preferencesStore ).get( 'core', 'showIconLabels' ),
[]
);

return (
<ToolbarDropdownMenu
popoverProps={ POPOVER_PROPS }
icon={ <HeadingLevelIcon level={ value } /> }
label={ __( 'Change level' ) }
controls={ validOptions.map( ( targetLevel ) => {
const isActive = targetLevel === value;
const title =
targetLevel === 0
? __( 'Paragraph' )
: sprintf(
// translators: %d: heading level e.g: "1", "2", "3"
__( 'Heading %d' ),
targetLevel
);

return {
icon: <HeadingLevelIcon level={ targetLevel } />,
title:
targetLevel === 0
? __( 'Paragraph' )
: sprintf(
// translators: %d: heading level e.g: "1", "2", "3"
__( 'Heading %d' ),
targetLevel
),
title: showIconLabels ? title : undefined,
isActive,
onClick() {
onChange( targetLevel );
Expand Down
Loading