[wp-trac] [WordPress Trac] #49025: Twenty Twenty: Modal menu link with hash should scroll to that section on the page.

WordPress Trac noreply at wordpress.org
Wed Dec 18 08:13:10 UTC 2019


#49025: Twenty Twenty: Modal menu link with hash should scroll to that section on
the page.
----------------------------+-----------------------------
 Reporter:  acosmin         |      Owner:  (none)
     Type:  defect (bug)    |     Status:  new
 Priority:  normal          |  Milestone:  Awaiting Review
Component:  Bundled Theme   |    Version:  5.3.1
 Severity:  normal          |   Keywords:
  Focuses:  ui, javascript  |
----------------------------+-----------------------------
 Based on this support ticket: https://wordpress.org/support/topic
 /possible-bug-anchor-links-dont-work-in-js-flow-out-menu/

 A possible fix would be to add this code in `index.js`, after
 [https://github.com/WordPress/WordPress/blob/c67763478840fabf689ecbd175dc682da1623069
 /wp-content/themes/twentytwenty/assets/js/index.js#L156 line 156]:


 {{{
 goToAnchor: function() {
         document.addEventListener( 'click', function( event ) {
                 var target = event.target;

                 if ( target.closest( '.modal-menu' ) && 'a' ===
 target.tagName.toLowerCase() ) {
                         var url, targetHref;

                         url = location.href.split( '#' )[ 0 ];
                         targetHref = target.href;

                         this.untoggleModal( target.closest( '.cover-
 modal.active' ) );

                         if( '' !== target.hash && -1 !==
 targetHref.indexOf( url ) ) {
                                 setTimeout( function() {
                                         var fakeEl =
 document.createElement( 'a' );

                                         fakeEl.href = targetHref;
                                         fakeEl.click();
                                 }, 550 );
                         }
                 }
         }.bind( this ) );
 },
 }}}

 And after
 [https://github.com/WordPress/WordPress/blob/c67763478840fabf689ecbd175dc682da1623069
 /wp-content/themes/twentytwenty/assets/js/index.js#L105 line 105], a call
 to the method: `this.goToAnchor();`

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/49025>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list