Make WordPress Core

Changeset 52003


Ignore:
Timestamp:
11/03/2021 03:04:55 PM (2 years ago)
Author:
hellofromTonya
Message:

Customize: Fix focus() to collapse child panels and show parent panel.

When a child panel is open, wp.customize.panel('parent_panel').focus() (e.g. 'parent_parent' might be 'nav_menus') collapses the child panel(s) to show the parent panel.

Follow-up to [30102], [31920], [38648].

Props celloexpressions, costdev, dlh, hareesh-pillai, hellofromTonya, westonruter, wpweaver.
Fixes #34436.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/wp/customize/controls.js

    r51683 r52003  
    696696     */
    697697    focus = function ( params ) {
    698         var construct, completeCallback, focus, focusElement;
     698        var construct, completeCallback, focus, focusElement, sections;
    699699        construct = this;
    700700        params = params || {};
    701701        focus = function () {
     702            // If a child section is currently expanded, collapse it.
     703            if ( construct.extended( api.Panel ) ) {
     704                sections = construct.sections();
     705                if ( 1 < sections.length ) {
     706                    sections.forEach( function ( section ) {
     707                        if ( section.expanded() ) {
     708                            section.collapse();
     709                        }
     710                    } );
     711                }
     712            }
     713
    702714            var focusContainer;
    703715            if ( ( construct.extended( api.Panel ) || construct.extended( api.Section ) ) && construct.expanded && construct.expanded() ) {
Note: See TracChangeset for help on using the changeset viewer.