Skip to content

Commit

Permalink
Gallery: remove unnecessary caption state (#44383)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix authored Sep 23, 2022
1 parent 4a61eb8 commit b75e560
Showing 1 changed file with 1 addition and 31 deletions.
32 changes: 1 addition & 31 deletions packages/block-library/src/gallery/gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
__experimentalGetElementClassName,
} from '@wordpress/block-editor';
import { VisuallyHidden } from '@wordpress/components';
import { useState, useEffect } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { createBlock, getDefaultBlockName } from '@wordpress/blocks';
import { View } from '@wordpress/primitives';
Expand All @@ -38,26 +37,6 @@ export const Gallery = ( props ) => {
__experimentalLayout: { type: 'default', alignments: [] },
} );

const [ captionFocused, setCaptionFocused ] = useState( false );

function onFocusCaption() {
if ( ! captionFocused ) {
setCaptionFocused( true );
}
}

function removeCaptionFocus() {
if ( captionFocused ) {
setCaptionFocused( false );
}
}

useEffect( () => {
if ( ! isSelected ) {
setCaptionFocused( false );
}
}, [ isSelected ] );

return (
<figure
{ ...innerBlocksProps }
Expand All @@ -74,17 +53,12 @@ export const Gallery = ( props ) => {
>
{ children }
{ isSelected && ! children && (
<View
className="blocks-gallery-media-placeholder-wrapper"
onClick={ removeCaptionFocus }
>
<View className="blocks-gallery-media-placeholder-wrapper">
{ mediaPlaceholder }
</View>
) }
<RichTextVisibilityHelper
isHidden={ ! isSelected && RichText.isEmpty( caption ) }
captionFocused={ captionFocused }
onFocusCaption={ onFocusCaption }
tagName="figcaption"
className={ classnames(
'blocks-gallery-caption',
Expand All @@ -105,8 +79,6 @@ export const Gallery = ( props ) => {

function RichTextVisibilityHelper( {
isHidden,
captionFocused,
onFocusCaption,
className,
value,
placeholder,
Expand All @@ -125,8 +97,6 @@ function RichTextVisibilityHelper( {
placeholder={ placeholder }
className={ className }
tagName={ tagName }
isSelected={ captionFocused }
onClick={ onFocusCaption }
{ ...richTextProps }
/>
);
Expand Down

0 comments on commit b75e560

Please sign in to comment.