Skip to content

Commit

Permalink
Exit early from onClick handler when isButtonDisabled (#12885)
Browse files Browse the repository at this point in the history
* disable onClick event when button is disabled

* clean up unit tests after click handler change
  • Loading branch information
Adam Silverstein authored and youknowriad committed Jan 3, 2019
1 parent 66556d7 commit 3118f59
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
3 changes: 3 additions & 0 deletions packages/editor/src/components/post-publish-button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ export class PostPublishButton extends Component {
}

const onClick = () => {
if ( isButtonDisabled ) {
return;
}
onSubmit();
onStatusChange( publishStatus );
onSave();
Expand Down
21 changes: 16 additions & 5 deletions packages/editor/src/components/post-publish-button/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ describe( 'PostPublishButton', () => {
<PostPublishButton
hasPublishAction={ false }
onStatusChange={ onStatusChange }
onSave={ onSave } />
onSave={ onSave }
isSaveable={ true }
isPublishable={ true }
/>
);

wrapper.simulate( 'click' );
Expand All @@ -119,7 +122,9 @@ describe( 'PostPublishButton', () => {
hasPublishAction={ true }
onStatusChange={ onStatusChange }
onSave={ onSave }
isBeingScheduled />
isBeingScheduled
isSaveable={ true }
isPublishable={ true } />
);

wrapper.simulate( 'click' );
Expand All @@ -135,7 +140,9 @@ describe( 'PostPublishButton', () => {
hasPublishAction={ true }
onStatusChange={ onStatusChange }
onSave={ onSave }
visibility="private" />
visibility="private"
isSaveable={ true }
isPublishable={ true } />
);

wrapper.simulate( 'click' );
Expand All @@ -150,7 +157,9 @@ describe( 'PostPublishButton', () => {
<PostPublishButton
hasPublishAction={ true }
onStatusChange={ onStatusChange }
onSave={ onSave } />
onSave={ onSave }
isSaveable={ true }
isPublishable={ true } />
);

wrapper.simulate( 'click' );
Expand All @@ -167,7 +176,9 @@ describe( 'PostPublishButton', () => {
<PostPublishButton
hasPublishAction={ true }
onStatusChange={ onStatusChange }
onSave={ onSave } />
onSave={ onSave }
isSaveable={ true }
isPublishable={ true } />
);

wrapper.simulate( 'click' );
Expand Down

0 comments on commit 3118f59

Please sign in to comment.