Skip to content
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
49 changes: 2 additions & 47 deletions packages/block-library/src/paragraph/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,11 @@ import {
InspectorControls,
RichText,
useBlockProps,
getFontSize,
__experimentalUseEditorFeature as useEditorFeature,
store as blockEditorStore,
} from '@wordpress/block-editor';
import { createBlock } from '@wordpress/blocks';
import { useSelect } from '@wordpress/data';
import { useEffect, useRef, useState } from '@wordpress/element';
import { formatLtr } from '@wordpress/icons';

function getComputedStyle( node, pseudo ) {
return node.ownerDocument.defaultView.getComputedStyle( node, pseudo );
}

const name = 'core/paragraph';

function ParagraphRTLToolbar( { direction, setDirection } ) {
Expand All @@ -50,23 +42,6 @@ function ParagraphRTLToolbar( { direction, setDirection } ) {
);
}

function useDropCapMinHeight( ref, isDisabled, dependencies ) {
const [ minHeight, setMinHeight ] = useState();

useEffect( () => {
if ( isDisabled ) {
setMinHeight();
return;
}

setMinHeight(
getComputedStyle( ref.current, 'first-letter' ).lineHeight
);
}, [ isDisabled, ...dependencies ] );

return minHeight;
}

function ParagraphBlock( {
attributes,
mergeBlocks,
Expand All @@ -75,34 +50,14 @@ function ParagraphBlock( {
setAttributes,
clientId,
} ) {
const {
align,
content,
direction,
dropCap,
placeholder,
fontSize,
style,
} = attributes;
const { align, content, direction, dropCap, placeholder } = attributes;
const isDropCapFeatureEnabled = useEditorFeature( 'typography.dropCap' );
const ref = useRef();
const inlineFontSize = style?.fontSize;
const size = useSelect(
( select ) => {
const { fontSizes } = select( blockEditorStore ).getSettings();
return getFontSize( fontSizes, fontSize, inlineFontSize ).size;
},
[ fontSize, inlineFontSize ]
);
const hasDropCap = isDropCapFeatureEnabled && dropCap;
const minHeight = useDropCapMinHeight( ref, ! hasDropCap, [ size ] );
const blockProps = useBlockProps( {
ref,
className: classnames( {
'has-drop-cap': dropCap,
[ `has-text-align-${ align }` ]: align,
} ),
style: { direction, minHeight },
style: { direction },
} );

return (
Expand Down
5 changes: 5 additions & 0 deletions packages/block-library/src/paragraph/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
font-style: normal;
}

// Prevent the dropcap from breaking out of the box when a background is applied.
p.has-drop-cap.has-background {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this happen regardless of background?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've been a bit back and forth on this one. If we do this, then it ends up looking like this:

But I would argue that the 2nd paragraph should be allowed to wrap around the dropcap, like this:

By limiting it to a paragraph that has a background, at least we allow this:

Screenshot 2021-03-01 at 11 49 21

overflow: hidden;
}

p.has-background {
padding: $block-bg-padding--v $block-bg-padding--h;
}
Expand Down