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

Stop displaying FontSizePicker dropdown when there are no fonts. #13782

Merged
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
82 changes: 42 additions & 40 deletions packages/components/src/font-size-picker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,47 +41,49 @@ function FontSizePicker( {
return (
<BaseControl label={ __( 'Font Size' ) }>
<div className="components-font-size-picker__buttons">
<Dropdown
className="components-font-size-picker__dropdown"
contentClassName="components-font-size-picker__dropdown-content"
position="bottom"
renderToggle={ ( { isOpen, onToggle } ) => (
<Button
className="components-font-size-picker__selector"
isLarge
onClick={ onToggle }
aria-expanded={ isOpen }
aria-label={ sprintf(
/* translators: %s: font size name */
__( 'Font size: %s' ), currentFontSizeName
) }
>
{ currentFontSizeName }
</Button>
) }
renderContent={ () => (
<NavigableMenu>
{ map( fontSizes, ( { name, size, slug } ) => {
const isSelected = ( value === size || ( ! value && slug === 'normal' ) );
{ ( fontSizes.length > 0 ) &&
<Dropdown
className="components-font-size-picker__dropdown"
contentClassName="components-font-size-picker__dropdown-content"
position="bottom"
renderToggle={ ( { isOpen, onToggle } ) => (
<Button
className="components-font-size-picker__selector"
isLarge
onClick={ onToggle }
aria-expanded={ isOpen }
aria-label={ sprintf(
/* translators: %s: font size name */
__( 'Font size: %s' ), currentFontSizeName
) }
>
{ currentFontSizeName }
</Button>
) }
renderContent={ () => (
<NavigableMenu>
{ map( fontSizes, ( { name, size, slug } ) => {
const isSelected = ( value === size || ( ! value && slug === 'normal' ) );

return (
<Button
key={ slug }
onClick={ () => onChange( slug === 'normal' ? undefined : size ) }
className={ `is-font-${ slug }` }
role="menuitemradio"
aria-checked={ isSelected }
>
{ isSelected && <Dashicon icon="saved" /> }
<span className="components-font-size-picker__dropdown-text-size" style={ { fontSize: size } }>
{ name }
</span>
</Button>
);
} ) }
</NavigableMenu>
) }
/>
return (
<Button
key={ slug }
onClick={ () => onChange( slug === 'normal' ? undefined : size ) }
className={ `is-font-${ slug }` }
role="menuitemradio"
aria-checked={ isSelected }
>
{ isSelected && <Dashicon icon="saved" /> }
<span className="components-font-size-picker__dropdown-text-size" style={ { fontSize: size } }>
{ name }
</span>
</Button>
);
} ) }
</NavigableMenu>
) }
/>
}
{ ( ! withSlider && ! disableCustomFontSizes ) &&
<input
className="components-range-control__number"
Expand Down