From e6e51414c9b7f6b05852780da818d234c20e7173 Mon Sep 17 00:00:00 2001 From: Tonya Mork Date: Wed, 3 Nov 2021 15:04:55 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@52003 602fd350-edb4-49c9-b593-d223f7449a82 --- src/js/_enqueues/wp/customize/controls.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/js/_enqueues/wp/customize/controls.js b/src/js/_enqueues/wp/customize/controls.js index 315e42d4c8..00ec7e2599 100644 --- a/src/js/_enqueues/wp/customize/controls.js +++ b/src/js/_enqueues/wp/customize/controls.js @@ -695,10 +695,22 @@ * @param {Function} [params.completeCallback] */ focus = function ( params ) { - var construct, completeCallback, focus, focusElement; + var construct, completeCallback, focus, focusElement, sections; construct = this; params = params || {}; focus = function () { + // If a child section is currently expanded, collapse it. + if ( construct.extended( api.Panel ) ) { + sections = construct.sections(); + if ( 1 < sections.length ) { + sections.forEach( function ( section ) { + if ( section.expanded() ) { + section.collapse(); + } + } ); + } + } + var focusContainer; if ( ( construct.extended( api.Panel ) || construct.extended( api.Section ) ) && construct.expanded && construct.expanded() ) { focusContainer = construct.contentContainer;