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

"onDismiss" option in "createInfoNotice" is not taken into account #31571

Closed
kmgalanakis opened this issue May 6, 2021 · 2 comments · Fixed by #32338
Closed

"onDismiss" option in "createInfoNotice" is not taken into account #31571

kmgalanakis opened this issue May 6, 2021 · 2 comments · Fixed by #32338
Labels
Good First Issue An issue that's suitable for someone looking to contribute for the first time Needs Dev Ready for, and needs developer efforts [Package] Components /packages/components [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended

Comments

@kmgalanakis
Copy link

When using wp.data.dispatch( 'core/notices' ).createInfoNotice and trying to pass a function for the onDismiss option, the function is not triggered when the notice is dismissed.

Typing something like wp.data.dispatch( 'core/notices' ).createInfoNotice( 'hello', { onDismiss: () => { console.log( 'dismissed!' ) } } ); is not logging anything in the console, when the created notice is dismissed.

Further information can be found here.

@paaljoachim paaljoachim added the Needs Technical Feedback Needs testing from a developer perspective. label May 6, 2021
@talldan talldan added [Package] Components /packages/components [Type] Bug An existing feature does not function as intended Good First Issue An issue that's suitable for someone looking to contribute for the first time and removed Needs Technical Feedback Needs testing from a developer perspective. labels May 7, 2021
@talldan
Copy link
Contributor

talldan commented May 7, 2021

Seems like this was implemented for Snackbar notices in #26952, but the implementation wasn't extended to normal notices.

Hopefully it should be a simple matter of implementing the onDismiss in the Notice component, and the implementation in Snackbar can serve as a good guide.

@vdwijngaert
Copy link
Member

vdwijngaert commented May 7, 2021

Hey @talldan,

I checked it out yesterday when the question arose on slack, should be an easy fix. Something like replacing

const removeNotice = ( id ) => () => onRemove( id );
with

const removeNotice = ( notice ) => () => {
   if( notice.onDismiss ) {
      notice.onDismiss( notice.id );
   }
   onRemove(notice.id);
};

This is where Snackbar did it:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good First Issue An issue that's suitable for someone looking to contribute for the first time Needs Dev Ready for, and needs developer efforts [Package] Components /packages/components [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants