diff --git a/packages/editor/src/components/post-url/index.js b/packages/editor/src/components/post-url/index.js
index c2b2ac8826b20..3d912af1ca453 100644
--- a/packages/editor/src/components/post-url/index.js
+++ b/packages/editor/src/components/post-url/index.js
@@ -16,7 +16,7 @@ import {
import { store as noticesStore } from '@wordpress/notices';
import { copySmall } from '@wordpress/icons';
import { store as coreStore } from '@wordpress/core-data';
-import { useCopyToClipboard } from '@wordpress/compose';
+import { useCopyToClipboard, useInstanceId } from '@wordpress/compose';
/**
* Internal dependencies
@@ -69,21 +69,28 @@ export default function PostURL( { onClose } ) {
const { createNotice } = useDispatch( noticesStore );
const [ forceEmptyField, setForceEmptyField ] = useState( false );
const copyButtonRef = useCopyToClipboard( permalink, () => {
- createNotice( 'info', __( 'Copied URL to clipboard.' ), {
+ createNotice( 'info', __( 'Copied Permalink to clipboard.' ), {
isDismissible: true,
type: 'snackbar',
} );
} );
+ const postUrlSlugDescriptionId =
+ 'editor-post-url__slug-descriotion-' + useInstanceId( PostURL );
+
return (
{ isEditable && (
-
- { __( 'Customize the last part of the URL. ' ) }
+
+
+ { __(
+ 'Customize the last part of the Permalink. '
+ ) }
+
{ __( 'Learn more.' ) }
-
+
) }
{ isEditable && (
-
- /
-
- }
- suffix={
-
- }
- label={ __( 'Link' ) }
- hideLabelFromVision
- value={ forceEmptyField ? '' : postSlug }
- autoComplete="off"
- spellCheck="false"
- type="text"
- className="editor-post-url__input"
- onChange={ ( newValue ) => {
- editPost( { slug: newValue } );
- // When we delete the field the permalink gets
- // reverted to the original value.
- // The forceEmptyField logic allows the user to have
- // the field temporarily empty while typing.
- if ( ! newValue ) {
- if ( ! forceEmptyField ) {
- setForceEmptyField( true );
- }
- return;
- }
- if ( forceEmptyField ) {
- setForceEmptyField( false );
+ <>
+
+ /
+
}
- } }
- onBlur={ ( event ) => {
- editPost( {
- slug: cleanForSlug( event.target.value ),
- } );
- if ( forceEmptyField ) {
- setForceEmptyField( false );
+ suffix={
+
}
- } }
- help={
+ label={ __( 'Slug' ) }
+ hideLabelFromVision
+ value={ forceEmptyField ? '' : postSlug }
+ autoComplete="off"
+ spellCheck="false"
+ type="text"
+ className="editor-post-url__input"
+ onChange={ ( newValue ) => {
+ editPost( { slug: newValue } );
+ // When we delete the field the permalink gets
+ // reverted to the original value.
+ // The forceEmptyField logic allows the user to have
+ // the field temporarily empty while typing.
+ if ( ! newValue ) {
+ if ( ! forceEmptyField ) {
+ setForceEmptyField( true );
+ }
+ return;
+ }
+ if ( forceEmptyField ) {
+ setForceEmptyField( false );
+ }
+ } }
+ onBlur={ ( event ) => {
+ editPost( {
+ slug: cleanForSlug(
+ event.target.value
+ ),
+ } );
+ if ( forceEmptyField ) {
+ setForceEmptyField( false );
+ }
+ } }
+ aria-describedby={ postUrlSlugDescriptionId }
+ />
+
+
+ { __( 'Permalink:' ) }
+
- }
- />
+
+ >
) }
{ ! isEditable && (
{
+ const { getCurrentPostId } = select( editorStore );
+ const { getEditedEntityRecord, canUser } = select( coreStore );
+ const siteSettings = canUser( 'read', {
+ kind: 'root',
+ name: 'site',
+ } )
+ ? getEditedEntityRecord( 'root', 'site' )
+ : undefined;
+ const _id = getCurrentPostId();
+ return {
+ isFrontPage: siteSettings?.page_on_front === _id,
+ };
+ }, [] );
// Use internal state instead of a ref to make sure that the component
// re-renders when the popover's anchor updates.
const [ popoverAnchor, setPopoverAnchor ] = useState( null );
@@ -38,41 +52,38 @@ export default function PostURLPanel() {
[ popoverAnchor ]
);
+ const label = isFrontPage ? __( 'Link' ) : __( 'Slug' );
+
return (
-
- (
-
- ) }
- renderContent={ ( { onClose } ) => (
-
- ) }
- />
+
+ { ! isFrontPage && (
+ (
+
+ ) }
+ renderContent={ ( { onClose } ) => (
+
+ ) }
+ />
+ ) }
+ { isFrontPage && }
);
}
function PostURLToggle( { isOpen, onClick } ) {
- const { slug, isFrontPage, postLink } = useSelect( ( select ) => {
- const { getCurrentPostId, getCurrentPost } = select( editorStore );
- const { getEditedEntityRecord, canUser } = select( coreStore );
- const siteSettings = canUser( 'read', {
- kind: 'root',
- name: 'site',
- } )
- ? getEditedEntityRecord( 'root', 'site' )
- : undefined;
- const _id = getCurrentPostId();
+ const { slug } = useSelect( ( select ) => {
return {
slug: select( editorStore ).getEditedPostSlug(),
- isFrontPage: siteSettings?.page_on_front === _id,
- postLink: getCurrentPost()?.link,
};
}, [] );
const decodedSlug = safeDecodeURIComponent( slug );
@@ -86,7 +97,26 @@ function PostURLToggle( { isOpen, onClick } ) {
aria-label={ sprintf( __( 'Change link: %s' ), decodedSlug ) }
onClick={ onClick }
>
- { isFrontPage ? postLink : <>/{ decodedSlug }> }
+ <>/{ decodedSlug }>
);
}
+
+function FrontPageLink() {
+ const { postLink } = useSelect( ( select ) => {
+ const { getCurrentPost } = select( editorStore );
+ return {
+ postLink: getCurrentPost()?.link,
+ };
+ }, [] );
+
+ return (
+
+ { postLink }
+
+ );
+}
diff --git a/packages/editor/src/components/post-url/style.scss b/packages/editor/src/components/post-url/style.scss
index c815f89682cb2..b6e9c510d2bc4 100644
--- a/packages/editor/src/components/post-url/style.scss
+++ b/packages/editor/src/components/post-url/style.scss
@@ -9,14 +9,19 @@
}
/* rtl:begin:ignore */
-.editor-post-url__link {
+.editor-post-url__link,
+.editor-post-url__front-page-link {
direction: ltr;
word-break: break-word;
- margin-top: $grid-unit-05;
- color: $gray-700;
}
/* rtl:end:ignore */
+.editor-post-url__front-page-link {
+ // Match padding on tertiary buttons for alignment.
+ padding: $grid-unit-15 * 0.5 0 $grid-unit-15 * 0.5 $grid-unit-15;
+}
+
+
.editor-post-url__link-slug {
font-weight: 600;
}
@@ -30,3 +35,16 @@
.editor-post-url__panel-toggle {
word-break: break-word;
}
+
+.editor-post-url__intro {
+ margin-bottom: 0;
+}
+
+.editor-post-url__permalink {
+ margin-top: $grid-unit-10;
+ margin-bottom: 0;
+
+ &-visual-label {
+ display: block;
+ }
+}