#52638 closed defect (bug) (fixed)
JS error when clicking a submenu heading on the collapsed admin menu
| Reported by: | SergeyBiryukov | Owned by: | SergeyBiryukov |
|---|---|---|---|
| Priority: | normal | Milestone: | 5.7 |
| Component: | Administration | Version: | |
| Severity: | normal | Keywords: | commit dev-reviewed |
| Cc: | Focuses: | ui |
Description
Reported by @peterwilsoncc in comment:82:ticket:51812:
Overnight I twigged to another regression in [50420] -- in a few places
$thing.get(0).trigger()is used. These will need to be changed to$thing.eq(0).trigger()as jQuery'sget()function returns a DOM element rather than a jQuery object.
I've found a single instance of this in js/_enqueues/admin/common.js:
- Click the "Collapse menu" button at the bottom of the admin menu.
- Hover any icon and click the submenu heading (with the
.wp-submenu-headclass), e.g. "Posts". - You'll get an error in the console:
Uncaught TypeError: $(...).parent(...).siblings(...).get(...).trigger is not a function at HTMLLIElement.<anonymous> (common.js?ver=5.8-alpha-20210224.134900:843) at HTMLUListElement.dispatch (jquery.js?ver=3.5.1:5429) at HTMLUListElement.elemData.handle (jquery.js?ver=3.5.1:5233)
Same as in [50383], the click() method there is not the jQuery method, but is an HTML DOM method instead, so the change to that line can be reverted.
Change History (7)
#2
@
6 years ago
Agreed, the old format should be used here, as the native .click() will be more performant (if negligible in this scenario) than going via jQuery any way.
#4
@
6 years ago
- Keywords commit dev-feedback added
- Resolution fixed
- Status closed → reopened
Reopening for backporting to the 5.7 branch after a second committer's review.
#5
@
6 years ago
- Keywords dev-reviewed added; dev-feedback removed
This looks good to commit to 5.7.
Review notes:
- Ran
npm run grunt clean -- --dev - Searched
./src/js/_enqueues/**/*.jsfor the string.get( - Remaining items appear to be calling the correct native function/from or for another library
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
In my testing, replacing
$thing.get(0).trigger( 'click' )with$thing.eq(0).trigger( 'click' )removes the console error, but for some reason does not make the submenu heading clickable.Reverting to
$thing.get(0).click();seems to work as expected, so I think we can go with that for now.