[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
Tue Jan 14 09:41:51 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):

 I found the issue. It was related to the Menu Image
 (https://de.wordpress.org/plugins/menu-image/) plugin since it creates
 `span` elements within the `a` link elements of the menu if images are
 present.

 This would then trigger the click event on the `span` instead of the `a`
 resulting in `'a' === target.tagName.toLowerCase()` returning `false`.

 my temporary solution looks like this:
 {{{
         goToAnchor: function () {
                 document.addEventListener('click', function (event) {
                         var target = event.target.closest('a');

                         if (target && 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));
         },
 }}}

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


More information about the wp-trac mailing list