From 3118f59141c73436f0f97ac36744bef669baa241 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Fri, 21 Dec 2018 02:06:14 -0700 Subject: [PATCH] Exit early from onClick handler when isButtonDisabled (#12885) * disable onClick event when button is disabled * clean up unit tests after click handler change --- .../components/post-publish-button/index.js | 3 +++ .../post-publish-button/test/index.js | 21 ++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/packages/editor/src/components/post-publish-button/index.js b/packages/editor/src/components/post-publish-button/index.js index cfed6dbd112f53..18eba3606e7118 100644 --- a/packages/editor/src/components/post-publish-button/index.js +++ b/packages/editor/src/components/post-publish-button/index.js @@ -73,6 +73,9 @@ export class PostPublishButton extends Component { } const onClick = () => { + if ( isButtonDisabled ) { + return; + } onSubmit(); onStatusChange( publishStatus ); onSave(); diff --git a/packages/editor/src/components/post-publish-button/test/index.js b/packages/editor/src/components/post-publish-button/test/index.js index 8fbef6007144a0..30156438cc14f1 100644 --- a/packages/editor/src/components/post-publish-button/test/index.js +++ b/packages/editor/src/components/post-publish-button/test/index.js @@ -103,7 +103,10 @@ describe( 'PostPublishButton', () => { + onSave={ onSave } + isSaveable={ true } + isPublishable={ true } + /> ); wrapper.simulate( 'click' ); @@ -119,7 +122,9 @@ describe( 'PostPublishButton', () => { hasPublishAction={ true } onStatusChange={ onStatusChange } onSave={ onSave } - isBeingScheduled /> + isBeingScheduled + isSaveable={ true } + isPublishable={ true } /> ); wrapper.simulate( 'click' ); @@ -135,7 +140,9 @@ describe( 'PostPublishButton', () => { hasPublishAction={ true } onStatusChange={ onStatusChange } onSave={ onSave } - visibility="private" /> + visibility="private" + isSaveable={ true } + isPublishable={ true } /> ); wrapper.simulate( 'click' ); @@ -150,7 +157,9 @@ describe( 'PostPublishButton', () => { + onSave={ onSave } + isSaveable={ true } + isPublishable={ true } /> ); wrapper.simulate( 'click' ); @@ -167,7 +176,9 @@ describe( 'PostPublishButton', () => { + onSave={ onSave } + isSaveable={ true } + isPublishable={ true } /> ); wrapper.simulate( 'click' );