Skip to content
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

[Social Link]: Correctly position the link popover when List View is open #32525

Merged
merged 1 commit into from
Jun 10, 2021
Merged
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
72 changes: 45 additions & 27 deletions packages/block-library/src/social-link/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
URLInput,
useBlockProps,
} from '@wordpress/block-editor';
import { Fragment, useState } from '@wordpress/element';
import { Fragment, useState, useRef } from '@wordpress/element';
import {
Button,
PanelBody,
Expand All @@ -27,6 +27,42 @@ import { keyboardReturn } from '@wordpress/icons';
*/
import { getIconBySite, getNameBySite } from './social-list';

const SocialLinkURLPopover = ( {
url,
setAttributes,
setPopover,
anchorRef,
} ) => (
<URLPopover
anchorRef={ anchorRef?.current }
onClose={ () => setPopover( false ) }
>
<form
className="block-editor-url-popover__link-editor"
onSubmit={ ( event ) => {
event.preventDefault();
setPopover( false );
} }
>
<div className="block-editor-url-input">
<URLInput
value={ url }
onChange={ ( nextURL ) =>
setAttributes( { url: nextURL } )
}
placeholder={ __( 'Enter address' ) }
disableSuggestions={ true }
/>
</div>
<Button
icon={ keyboardReturn }
label={ __( 'Apply' ) }
type="submit"
/>
</form>
</URLPopover>
);

const SocialLinkEdit = ( {
attributes,
context,
Expand All @@ -40,6 +76,7 @@ const SocialLinkEdit = ( {
'wp-social-link__is-incomplete': ! url,
} );

const ref = useRef();
const IconComponent = getIconBySite( service );
const socialLinkName = getNameBySite( service );
const blockProps = useBlockProps( {
Expand Down Expand Up @@ -76,34 +113,15 @@ const SocialLinkEdit = ( {
</PanelBody>
</InspectorControls>
<li { ...blockProps }>
<Button onClick={ () => setPopover( true ) }>
<Button ref={ ref } onClick={ () => setPopover( true ) }>
<IconComponent />
{ isSelected && showURLPopover && (
<URLPopover onClose={ () => setPopover( false ) }>
<form
className="block-editor-url-popover__link-editor"
onSubmit={ ( event ) => {
event.preventDefault();
setPopover( false );
} }
>
<div className="block-editor-url-input">
<URLInput
value={ url }
onChange={ ( nextURL ) =>
setAttributes( { url: nextURL } )
}
placeholder={ __( 'Enter address' ) }
disableSuggestions={ true }
/>
</div>
<Button
icon={ keyboardReturn }
label={ __( 'Apply' ) }
type="submit"
/>
</form>
</URLPopover>
<SocialLinkURLPopover
url={ url }
setAttributes={ setAttributes }
setPopover={ setPopover }
anchorRef={ ref }
/>
) }
</Button>
</li>
Expand Down