[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 Apr 22 17:05:12 UTC 2020


#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         |  Resolution:
 Keywords:                 |     Focuses:  ui, javascript
---------------------------+------------------------------

Comment (by raQai):

 Replying to [comment:3 bdcstr]:
 > Noticed the same issue. This is my **temporary-and-not-perfect**
 solution (so don't judge me!) while waiting for the official patch.
 >
 > 1. Go to themes/twentytwenty/assets/js/index.js
 > 2. Look for the `outsideUntoggle: function () {` (at line 135 for me)
 > 3. Change with the following code:
 >
 > {{{
 >     outsideUntoggle: function () {
 >         document.addEventListener('click', function (event) {
 >             var target = event.target;
 >             var modal = document.querySelector('.cover-modal.active');
 >
 >             if (event.target.tagName.toLowerCase() === 'a' &&
 event.target.hash.includes('#')) {
 >                 this.untoggleModal(modal);
 >                 setTimeout(function () {
 >                     var anchor =
 document.getElementById(event.target.hash.slice(1)); //
 >                     anchor.scrollIntoView();
 >                 }, 550);
 >             }
 >
 >             if (target === modal) {
 >                 this.untoggleModal(target);
 >             }
 >         }.bind(this));
 >     },
 > }}}
 >
 >
 > 4. Hope it helps ;)
 >
 > Cheers!

 This would by default use any anchor link on the current site.
 Using a menu link `/path/to/page1#anchor` would also scroll to `#anchor`
 on `/path/to/page2` if it is available.

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


More information about the wp-trac mailing list