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

Fix: The Copy button of the PostURL shouldn't be placed in the slug input #63706

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Open
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
61 changes: 37 additions & 24 deletions packages/components/src/external-link/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import type { ForwardedRef } from 'react';
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { forwardRef } from '@wordpress/element';
import { Fragment, forwardRef } from '@wordpress/element';

/**
* Internal dependencies
*/
import type { ExternalLinkProps } from './types';
import type { WordPressComponentProps } from '../context';
import { Suffix } from '../input-control/styles/input-control-styles';

function UnforwardedExternalLink(
props: Omit<
Expand All @@ -23,7 +24,14 @@ function UnforwardedExternalLink(
>,
ref: ForwardedRef< HTMLAnchorElement >
) {
const { href, children, className, rel = '', ...additionalProps } = props;
const {
href,
children,
className,
rel = '',
suffix,
...additionalProps
} = props;
const optimizedRel = [
...new Set(
[
Expand Down Expand Up @@ -54,28 +62,33 @@ function UnforwardedExternalLink(

return (
/* eslint-disable react/jsx-no-target-blank */
<a
{ ...additionalProps }
className={ classes }
href={ href }
onClick={ onClickHandler }
target="_blank"
rel={ optimizedRel }
ref={ ref }
>
<span className="components-external-link__contents">
{ children }
</span>
<span
className="components-external-link__icon"
aria-label={
/* translators: accessibility text */
__( '(opens in a new tab)' )
}
>
&#8599;
</span>
</a>
<Fragment>
<div className="components-external-link__wrapper">
<a
{ ...additionalProps }
className={ classes }
href={ href }
onClick={ onClickHandler }
target="_blank"
rel={ optimizedRel }
ref={ ref }
>
<span className="components-external-link__contents">
{ children }
</span>
<span
className="components-external-link__icon"
aria-label={
/* translators: accessibility text */
__( '(opens in a new tab)' )
}
>
&#8599;
</span>
</a>
<div>{ suffix && <Suffix>{ suffix }</Suffix> }</div>
Copy link
Contributor

Choose a reason for hiding this comment

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

is the <div> necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, as I'm using space-between in styling so it was needed

</div>
</Fragment>
/* eslint-enable react/jsx-no-target-blank */
);
}
Expand Down
5 changes: 5 additions & 0 deletions packages/components/src/external-link/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ export type ExternalLinkProps = {
* The URL of the external resource.
*/
href: string;
/**
* Allows for markup other than icons or shortcuts to be added to the menu item.
Copy link
Contributor

Choose a reason for hiding this comment

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

This description should be adjusted, as this component isn't s 'menu item'.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, can you suggest a better description
Thanks

*
*/
suffix?: ReactNode;
};
14 changes: 7 additions & 7 deletions packages/editor/src/components/post-url/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,6 @@ export default function PostURL( { onClose } ) {
/
</InputControlPrefixWrapper>
}
suffix={
<Button
icon={ copySmall }
ref={ copyButtonRef }
label={ __( 'Copy' ) }
/>
}
label={ __( 'Link' ) }
hideLabelFromVision
value={ forceEmptyField ? '' : postSlug }
Expand Down Expand Up @@ -145,6 +138,13 @@ export default function PostURL( { onClose } ) {
className="editor-post-url__link"
href={ postLink }
target="_blank"
suffix={
<Button
icon={ copySmall }
ref={ copyButtonRef }
label={ __( 'Copy' ) }
/>
}
>
<span className="editor-post-url__link-prefix">
{ permalinkPrefix }
Expand Down
6 changes: 6 additions & 0 deletions packages/editor/src/components/post-url/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@
.editor-post-url__panel-toggle {
word-break: break-word;
}

.components-external-link__wrapper {
display: flex;
align-items: center;
justify-content: space-between;
}
Loading