WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#42682 closed enhancement (maybelater)

Allow customize notifications to be auto dismissed after a delay

Reported by: nikeo Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.9
Component: Customize Keywords:
Focuses: Cc:

Description

The notifications are one of the great recent additions to the customizer but there's currently no way to create auto dismissible notifications. Once rendered, it requires a user action to dismiss a notification.

My proposition is a basic way to implement this, by allowing the dismissible param to accept either a boolean param ( as it is right now ) or a number indicating the delay in milliseconds after which the notification should be auto dismissed.

As far as my tests went, there's no risk of regression when using this param with either a boolean or number.
Works fine when processing the notification template here : https://core.trac.wordpress.org/browser/trunk/src/wp-includes/class-wp-customize-manager.php#L4087

The example below illustrates how to add a notification auto dismissed after 5 seconds.

wp.customize.notifications.add( new wp.customize.Notification( 'auto_dismissible_notification', {
    type: 'info',
    message: 'This notification will be auto dismissed after 5 seconds',
    dismissible: 5000
} ) );

Attachments (1)

42682.patch (1.9 KB) - added by nikeo 3 years ago.

Download all attachments as: .zip

Change History (5)

@nikeo
3 years ago

#1 @westonruter
3 years ago

  • Keywords reporter-feedback added

I'm not aware of any notifications in core that auto-dismiss. What is the use case? A plugin can easily auto-dismiss a notification after a timeout. I don't know if core needs to support this itself.

#2 @nikeo
3 years ago

My use case is that I want to notify a user with an information without necessarily waiting for a manual dismiss. Simply displaying a contextual information.

I thought this could be useful for developers to allow this flexibility for the customizer notifications.

Typically, the following is an example of what I need to write to achieve that right now :

api.notifications.add( new api.Notification( 'widgets_are_sidewide', {
      type: 'info',
      message: serverControlParams.i18n['Widgets are created sitewide.'],
      dismissible: true
} ) );

// Removed if not dismissed after 5 seconds
_.delay( function() {
      if ( api.notifications.has( 'widgets_are_sidewide' ) ) {
            var _notif_ = api.notifications( 'widgets_are_sidewide' );
            _notif_.parent.remove( _notif_.code );
      }
}, 5000 );

While I would like to simply write :

api.notifications.add( new api.Notification( 'widgets_are_sidewide', {
      type: 'info',
      message: serverControlParams.i18n['Widgets are created sitewide.'],
      dismissible: 5000
} ) );
Last edited 3 years ago by nikeo (previous) (diff)

#3 follow-up: @westonruter
3 years ago

  • Keywords reporter-feedback removed
  • Milestone Awaiting Review deleted
  • Resolution set to maybelater
  • Status changed from new to closed

You can simplify your example removal code quite a bit to just:

_.delay( function() {
      api.notifications.remove( 'widgets_are_sidewide' );
}, 5000 );

That being the case, I don't think we should add support for “delayed auto-dismissal” into core since it is so trivial to do with with the existing API. If we find there are use cases for auto-dismissal in core, then we can revisit this.

#4 in reply to: ↑ 3 @nikeo
3 years ago

Replying to westonruter:

Ah yes that's right, my code included uncessary steps :)

Ok. Thanks for your quick feedback.

You can simplify your example removal code quite a bit to just:

_.delay( function() {
      api.notifications.remove( 'widgets_are_sidewide' );
}, 5000 );

That being the case, I don't think we should add support for “delayed auto-dismissal” into core since it is so trivial to do with with the existing API. If we find there are use cases for auto-dismissal in core, then we can revisit this.

Note: See TracTickets for help on using tickets.