-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Site Logo: Prevent focus loss when updating media from the sidebar #68621
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,8 +33,6 @@ import { | |
BlockControls, | ||
InspectorControls, | ||
MediaPlaceholder, | ||
MediaUpload, | ||
MediaUploadCheck, | ||
MediaReplaceFlow, | ||
useBlockProps, | ||
store as blockEditorStore, | ||
|
@@ -347,29 +345,24 @@ const SiteLogo = ( { | |
|
||
// This is a light wrapper around MediaReplaceFlow because the block has two | ||
// different MediaReplaceFlows, one for the inspector and one for the toolbar. | ||
function SiteLogoReplaceFlow( { | ||
mediaURL, | ||
onRemoveLogo, | ||
...mediaReplaceProps | ||
} ) { | ||
function SiteLogoReplaceFlow( { mediaURL, ...mediaReplaceProps } ) { | ||
return ( | ||
<MediaReplaceFlow | ||
{ ...mediaReplaceProps } | ||
mediaURL={ mediaURL } | ||
allowedTypes={ ALLOWED_MEDIA_TYPES } | ||
accept={ ACCEPT_MEDIA_STRING } | ||
onReset={ onRemoveLogo } | ||
/> | ||
); | ||
} | ||
|
||
const InspectorLogoPreview = ( { mediaItemData = {}, itemGroupProps } ) => { | ||
const InspectorLogoPreview = ( { media, itemGroupProps } ) => { | ||
const { | ||
alt_text: alt, | ||
source_url: logoUrl, | ||
slug: logoSlug, | ||
media_details: logoMediaDetails, | ||
} = mediaItemData; | ||
} = media ?? {}; | ||
const logoLabel = logoMediaDetails?.sizes?.full?.file || logoSlug; | ||
return ( | ||
<ItemGroup { ...itemGroupProps } as="span"> | ||
|
@@ -530,7 +523,7 @@ export default function LogoEdit( { | |
name: ! logoUrl ? __( 'Choose logo' ) : __( 'Replace' ), | ||
onSelect: onSelectLogo, | ||
onError: onUploadError, | ||
onRemoveLogo, | ||
onReset: onRemoveLogo, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just mapping callback to support prop. |
||
}; | ||
const controls = canUserEdit && ( | ||
<BlockControls group="other"> | ||
|
@@ -603,50 +596,40 @@ export default function LogoEdit( { | |
<InspectorControls> | ||
<PanelBody title={ __( 'Media' ) }> | ||
<div className="block-library-site-logo__inspector-media-replace-container"> | ||
{ ! canUserEdit && !! logoUrl && ( | ||
{ ! canUserEdit ? ( | ||
<InspectorLogoPreview | ||
mediaItemData={ mediaItemData } | ||
media={ mediaItemData } | ||
itemGroupProps={ { | ||
isBordered: true, | ||
className: | ||
'block-library-site-logo__inspector-readonly-logo-preview', | ||
} } | ||
/> | ||
) } | ||
{ canUserEdit && !! logoUrl && ( | ||
<SiteLogoReplaceFlow | ||
{ ...mediaReplaceFlowProps } | ||
name={ | ||
<InspectorLogoPreview | ||
mediaItemData={ mediaItemData } | ||
/> | ||
} | ||
popoverProps={ {} } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This prop was doing nothing. The |
||
/> | ||
) } | ||
{ canUserEdit && ! logoUrl && ( | ||
<MediaUploadCheck> | ||
<MediaUpload | ||
onSelect={ onInitialSelectLogo } | ||
allowedTypes={ ALLOWED_MEDIA_TYPES } | ||
render={ ( { open } ) => ( | ||
<div className="block-library-site-logo__inspector-upload-container"> | ||
<Button | ||
__next40pxDefaultSize | ||
onClick={ open } | ||
variant="secondary" | ||
> | ||
{ isLoading ? ( | ||
<Spinner /> | ||
) : ( | ||
__( 'Choose logo' ) | ||
) } | ||
</Button> | ||
<DropZone onFilesDrop={ onFilesDrop } /> | ||
</div> | ||
) : ( | ||
<> | ||
<SiteLogoReplaceFlow | ||
{ ...mediaReplaceFlowProps } | ||
name={ | ||
!! logoUrl ? ( | ||
<InspectorLogoPreview | ||
media={ mediaItemData } | ||
/> | ||
) : ( | ||
__( 'Choose logo' ) | ||
) | ||
} | ||
renderToggle={ ( props ) => ( | ||
<Button { ...props } __next40pxDefaultSize> | ||
{ temporaryURL ? ( | ||
<Spinner /> | ||
) : ( | ||
props.children | ||
) } | ||
</Button> | ||
Comment on lines
+621
to
+628
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixes spacing inconsistency with the button. See #68084. |
||
) } | ||
/> | ||
</MediaUploadCheck> | ||
<DropZone onFilesDrop={ onFilesDrop } /> | ||
</> | ||
) } | ||
</div> | ||
</PanelBody> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
media
can benull
, where the default parameter isn't used and triggers an error when deconstructing. Using fallback here prevents that.