Skip to content
Prev Previous commit
Next Next commit
Fix focusing on the back button
  • Loading branch information
kevin940726 committed May 4, 2021
commit 304003e310e1ed1833329d36c5f618935b42cdca
13 changes: 9 additions & 4 deletions packages/customize-widgets/src/components/focus-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,16 @@ export default function FocusControl( { api, sidebarControls, children } ) {
const widgets = sidebarControl.setting.get();

if ( widgets.includes( widgetId ) ) {
sidebarControl.sectionInstance.expand();
sidebarControl.sectionInstance.expand( {
// Schedule it after the complete callback so that
// it won't be overridden by the "Back" button focus.
completeCallback() {
// Create a "ref-like" object every time to ensure
// the same widget id can also triggers the focus control.
setFocusedWidgetIdRef( { current: widgetId } );
},
} );

// Create a "ref-like" object every time to ensure
// the same widget id can also triggers the focus control.
setFocusedWidgetIdRef( { current: widgetId } );
break;
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/customize-widgets/src/controls/sidebar-section.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export default function getSidebarSection() {
controls.forEach( ( control ) => {
control.onChangeSectionExpanded( expanded, args );
} );
_args.completeCallback?.();
},
};

Expand Down