Skip to content

Commit

Permalink
Swap position of the Pre-publish checks buttons. (WordPress#65317)
Browse files Browse the repository at this point in the history
* Swap position of the Pre-publish checks buttons.

* Adjust test.

Co-authored-by: afercia <afercia@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
Co-authored-by: jameskoster <jameskoster@git.wordpress.org>
  • Loading branch information
4 people committed Sep 19, 2024
1 parent 610aabe commit 6daffdb
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 51 deletions.
19 changes: 1 addition & 18 deletions packages/editor/src/components/post-publish-button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* WordPress dependencies
*/
import { Button } from '@wordpress/components';
import { Component, createRef } from '@wordpress/element';
import { Component } from '@wordpress/element';
import { withSelect, withDispatch } from '@wordpress/data';
import { compose } from '@wordpress/compose';

Expand All @@ -17,7 +17,6 @@ const noop = () => {};
export class PostPublishButton extends Component {
constructor( props ) {
super( props );
this.buttonNode = createRef();

this.createOnClick = this.createOnClick.bind( this );
this.closeEntitiesSavedStates =
Expand All @@ -28,21 +27,6 @@ export class PostPublishButton extends Component {
};
}

componentDidMount() {
if ( this.props.focusOnMount ) {
// This timeout is necessary to make sure the `useEffect` hook of
// `useFocusReturn` gets the correct element (the button that opens the
// PostPublishPanel) otherwise it will get this button.
this.timeoutID = setTimeout( () => {
this.buttonNode.current.focus();
}, 0 );
}
}

componentWillUnmount() {
clearTimeout( this.timeoutID );
}

createOnClick( callback ) {
return ( ...args ) => {
const { hasNonPostEntityChanges, setEntitiesSavedStatesCallback } =
Expand Down Expand Up @@ -182,7 +166,6 @@ export class PostPublishButton extends Component {
return (
<>
<Button
ref={ this.buttonNode }
{ ...componentProps }
className={ `${ componentProps.className } editor-post-publish-button__button` }
size="compact"
Expand Down
30 changes: 22 additions & 8 deletions packages/editor/src/components/post-publish-panel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { Component } from '@wordpress/element';
import { Component, createRef } from '@wordpress/element';
import {
Button,
Spinner,
Expand All @@ -27,6 +27,20 @@ export class PostPublishPanel extends Component {
constructor() {
super( ...arguments );
this.onSubmit = this.onSubmit.bind( this );
this.cancelButtonNode = createRef();
}

componentDidMount() {
// This timeout is necessary to make sure the `useEffect` hook of
// `useFocusReturn` gets the correct element (the button that opens the
// PostPublishPanel) otherwise it will get this button.
this.timeoutID = setTimeout( () => {
this.cancelButtonNode.current.focus();
}, 0 );
}

componentWillUnmount() {
clearTimeout( this.timeoutID );
}

componentDidUpdate( prevProps ) {
Expand Down Expand Up @@ -85,15 +99,9 @@ export class PostPublishPanel extends Component {
/>
) : (
<>
<div className="editor-post-publish-panel__header-publish-button">
<PostPublishButton
focusOnMount
onSubmit={ this.onSubmit }
forceIsDirty={ forceIsDirty }
/>
</div>
<div className="editor-post-publish-panel__header-cancel-button">
<Button
ref={ this.cancelButtonNode }
accessibleWhenDisabled
disabled={ isSavingNonPostEntityChanges }
onClick={ onClose }
Expand All @@ -103,6 +111,12 @@ export class PostPublishPanel extends Component {
{ __( 'Cancel' ) }
</Button>
</div>
<div className="editor-post-publish-panel__header-publish-button">
<PostPublishButton
onSubmit={ this.onSubmit }
forceIsDirty={ forceIsDirty }
/>
</div>
</>
) }
</div>
Expand Down
4 changes: 2 additions & 2 deletions packages/editor/src/components/post-publish-panel/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@
}

.editor-post-publish-panel__header-publish-button {
padding-right: $grid-unit-05;
padding-left: $grid-unit-05;
justify-content: center;
}

.editor-post-publish-panel__header-cancel-button {
padding-left: $grid-unit-05;
padding-right: $grid-unit-05;
}

.editor-post-publish-panel__header-published {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,24 +433,24 @@ exports[`PostPublishPanel should render the pre-publish panel if post status is
class="editor-post-publish-panel__header"
>
<div
class="editor-post-publish-panel__header-publish-button"
class="editor-post-publish-panel__header-cancel-button"
>
<button
aria-disabled="true"
class="components-button editor-post-publish-button editor-post-publish-button__button is-primary is-compact"
class="components-button is-secondary is-compact"
type="button"
>
Submit for Review
Cancel
</button>
</div>
<div
class="editor-post-publish-panel__header-cancel-button"
class="editor-post-publish-panel__header-publish-button"
>
<button
class="components-button is-secondary is-compact"
aria-disabled="true"
class="components-button editor-post-publish-button editor-post-publish-button__button is-primary is-compact"
type="button"
>
Cancel
Submit for Review
</button>
</div>
</div>
Expand Down Expand Up @@ -586,24 +586,24 @@ exports[`PostPublishPanel should render the pre-publish panel if the post is not
class="editor-post-publish-panel__header"
>
<div
class="editor-post-publish-panel__header-publish-button"
class="editor-post-publish-panel__header-cancel-button"
>
<button
aria-disabled="true"
class="components-button editor-post-publish-button editor-post-publish-button__button is-primary is-compact"
class="components-button is-secondary is-compact"
type="button"
>
Submit for Review
Cancel
</button>
</div>
<div
class="editor-post-publish-panel__header-cancel-button"
class="editor-post-publish-panel__header-publish-button"
>
<button
class="components-button is-secondary is-compact"
aria-disabled="true"
class="components-button editor-post-publish-button editor-post-publish-button__button is-primary is-compact"
type="button"
>
Cancel
Submit for Review
</button>
</div>
</div>
Expand Down Expand Up @@ -783,24 +783,24 @@ exports[`PostPublishPanel should render the spinner if the post is being saved 1
class="editor-post-publish-panel__header"
>
<div
class="editor-post-publish-panel__header-publish-button"
class="editor-post-publish-panel__header-cancel-button"
>
<button
aria-disabled="true"
class="components-button editor-post-publish-button editor-post-publish-button__button is-primary is-compact"
class="components-button is-secondary is-compact"
type="button"
>
Submit for Review
Cancel
</button>
</div>
<div
class="editor-post-publish-panel__header-cancel-button"
class="editor-post-publish-panel__header-publish-button"
>
<button
class="components-button is-secondary is-compact"
aria-disabled="true"
class="components-button editor-post-publish-button editor-post-publish-button__button is-primary is-compact"
type="button"
>
Cancel
Submit for Review
</button>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/specs/editor/various/publish-panel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ test.describe( 'Post publish panel', () => {
).toBeFocused();
} );

test( 'should move focus to the publish button in the panel', async ( {
test( 'should move focus to the cancel button in the panel', async ( {
editor,
page,
} ) => {
Expand All @@ -74,7 +74,7 @@ test.describe( 'Post publish panel', () => {
page
.getByRole( 'region', { name: 'Editor publish' } )
.locator( ':focus' )
).toHaveText( 'Publish' );
).toHaveText( 'Cancel' );
} );

test( 'should focus on the post list after publishing', async ( {
Expand Down

0 comments on commit 6daffdb

Please sign in to comment.