Skip to content

Commit d82c60f

Browse files
committed
Fix remove image bug caused due to blur event
1 parent c3e4b17 commit d82c60f

File tree

5 files changed

+21
-45
lines changed

5 files changed

+21
-45
lines changed

plugin/assets/src/block-editor/blocks/card/components/card-image-edit.js

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ const CardImageEdit = ( {
5656
cardPrimaryProps,
5757
cardIndex,
5858
setter,
59+
isFocused,
5960
} ) => {
6061
const [ hasImage, setHasImage ] = useState(
6162
imageSourceUrl !== undefined && imageSourceUrl !== ''
6263
);
63-
const [ isFocused, setIsFocused ] = useState( false );
6464

6565
useEffect( () => {
6666
if ( imageSourceUrl !== undefined && imageSourceUrl !== '' ) {
@@ -90,21 +90,6 @@ const CardImageEdit = ( {
9090
setHasImage( false );
9191
};
9292

93-
/**
94-
* Handle image container on blur event.
95-
*
96-
* @param {Object} event - Event.
97-
*/
98-
const onImageContainerBlur = event => {
99-
const currentTarget = event.currentTarget;
100-
/* istanbul ignore next */
101-
setTimeout( () => {
102-
if ( ! currentTarget.contains( document.activeElement ) ) {
103-
setIsFocused( false );
104-
}
105-
}, 0 );
106-
};
107-
10893
return (
10994
<>
11095
{ ( ! hasImage || isImageEditMode ) && displayImage && (
@@ -120,13 +105,7 @@ const CardImageEdit = ( {
120105
) }
121106
{ hasImage && ! isImageEditMode && imageSourceUrl && (
122107
<>
123-
<div
124-
className={ classnames( 'material-design-card__media-container', {
125-
'material-design-card__media-container-focused': isFocused,
126-
} ) }
127-
onFocus={ () => setIsFocused( true ) }
128-
onBlur={ onImageContainerBlur }
129-
>
108+
<div className="material-design-card__media-container">
130109
<div
131110
tabIndex={ 0 }
132111
className={ classnames(
@@ -145,19 +124,17 @@ const CardImageEdit = ( {
145124
</div>
146125
) }
147126
</div>
148-
<div
149-
className={ classnames( 'material-design-card__media-actions', {
150-
'material-design-card__media-actions-shown': isFocused,
151-
} ) }
152-
>
153-
<Button
154-
className="material-design-card__media-close-button"
155-
icon="no"
156-
showTooltip={ true }
157-
label={ __( 'Remove Card Image', 'material-design' ) }
158-
onClick={ onRemoveImage }
159-
/>
160-
</div>
127+
{ isFocused && (
128+
<div className="material-design-card__media-actions">
129+
<Button
130+
className="material-design-card__media-close-button"
131+
icon="no"
132+
showTooltip={ true }
133+
label={ __( 'Remove Card Image', 'material-design' ) }
134+
onClick={ onRemoveImage }
135+
/>
136+
</div>
137+
) }
161138
</div>
162139
</>
163140
) }

plugin/assets/src/block-editor/blocks/card/components/card-image.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const CardImage = ( {
5252
setter,
5353
isEditMode,
5454
} ) => {
55+
const { isFocused } = cardPrimaryProps;
5556
const cardImageEditProps = {
5657
imageSourceUrl,
5758
isImageEditMode,
@@ -62,6 +63,7 @@ const CardImage = ( {
6263
cardIndex,
6364
setter,
6465
isEditMode,
66+
isFocused,
6567
};
6668

6769
return (

plugin/assets/src/block-editor/blocks/card/components/horizontal-card-layout.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ const HorizontalCardLayout = ( {
104104
cardIndex,
105105
setter,
106106
isEditMode,
107+
isFocused,
107108
};
108109

109110
const styles = {};

plugin/assets/src/block-editor/blocks/card/components/vertical-card-layout.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ const VerticalCardLayout = ( {
9595
cardIndex,
9696
setter,
9797
isEditMode,
98+
isFocused,
9899
};
99100

100101
const cardImageProps = {

plugin/assets/src/block-editor/blocks/card/editor.css

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@
1414
* limitations under the License.
1515
*/
1616

17-
.material-design-card__media-container-focused {
18-
border: 4px rgb(0, 113, 161) solid;
19-
17+
.material-design-card__media-container {
18+
position: relative;
2019
}
2120

2221
.material-design-card__media-actions {
23-
display: none;
2422
position: absolute;
2523
right: 10px;
2624
top: 10px;
@@ -29,16 +27,13 @@
2927
border-radius: 4px;
3028
transition: box-shadow 0.2s ease-out;
3129
height: 27px;
30+
z-index: 10;
3231

33-
> button {
32+
& > button {
3433
height: 25px;
3534
}
3635
}
3736

38-
.material-design-card__media-actions-shown {
39-
display: block !important;
40-
}
41-
4237
.material-design-card__media-close-button {
4338
padding: 2px !important;
4439
}

0 commit comments

Comments
 (0)