Skip to content

Commit

Permalink
fix default controls
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiankaegy committed Dec 6, 2024
1 parent 89af211 commit f66ba18
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions packages/block-library/src/paragraph/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function hasDropCapDisabled( align ) {
return align === ( isRTL() ? 'left' : 'right' ) || align === 'center';
}

function DropCapControl( { clientId, attributes, setAttributes } ) {
function DropCapControl( { clientId, attributes, setAttributes, name } ) {
// Please do not add a useSelect call to the paragraph block unconditionally.
// Every useSelect added to a (frequently used) block will degrade load
// and type performance. By moving it within InspectorControls, the subscription is
Expand All @@ -70,17 +70,18 @@ function DropCapControl( { clientId, attributes, setAttributes } ) {
helpText = __( 'Show a large initial letter.' );
}

const defaultTypographyControls = getBlockSupport( name, [
'typography',
'__experimentalDefaultControls',
] );
const isDropCapControlEnabledByDefault = getBlockSupport(
name,
'typography.defaultControls.dropCap',
false
);

return (
<InspectorControls group="typography">
<ToolsPanelItem
hasValue={ () => !! dropCap }
label={ __( 'Drop cap' ) }
isShownByDefault={ defaultTypographyControls?.dropCap }
isShownByDefault={ isDropCapControlEnabledByDefault }
onDeselect={ () => setAttributes( { dropCap: undefined } ) }
resetAllFilter={ () => ( { dropCap: undefined } ) }
panelId={ clientId }
Expand All @@ -106,6 +107,7 @@ function ParagraphBlock( {
setAttributes,
clientId,
isSelected: isSingleSelected,
name,
} ) {
const { align, content, direction, dropCap, placeholder } = attributes;
const blockProps = useBlockProps( {
Expand Down Expand Up @@ -143,6 +145,7 @@ function ParagraphBlock( {
) }
{ isSingleSelected && (
<DropCapControl
name={ name }
clientId={ clientId }
attributes={ attributes }
setAttributes={ setAttributes }
Expand Down

0 comments on commit f66ba18

Please sign in to comment.