WordPress.org

Make WordPress Core

Ticket #35947: 35947.5.patch

File 35947.5.patch, 1.7 KB (added by delawski, 4 years ago)

Fix focus() inside widget customize control

  • src/wp-admin/js/customize-controls.js

    From 81b7b76a7c0b6d9bf4e5ee7482efa66cd6cca554 Mon Sep 17 00:00:00 2001
    From: Piotr Delawski <piotr.delawski@xwp.co>
    Date: Thu, 10 Mar 2016 14:48:05 +0100
    Subject: [PATCH] Fix `focus()` inside widget customize control (try to focus
     on form elements first, then on anchors and other elements).
    
    ---
     src/wp-admin/js/customize-controls.js | 10 ++++++++--
     1 file changed, 8 insertions(+), 2 deletions(-)
    
    diff --git a/src/wp-admin/js/customize-controls.js b/src/wp-admin/js/customize-controls.js
    index dbda12b..9be6b2b 100644
    a b  
    8181                construct = this;
    8282                params = params || {};
    8383                focus = function () {
    84                         var focusContainer;
     84                        var focusContainer, focusElement;
    8585                        if ( construct.extended( api.Panel ) && construct.expanded && construct.expanded() ) {
    8686                                focusContainer = construct.container.find( 'ul.control-panel-content' );
    8787                        } else if ( construct.extended( api.Section ) && construct.expanded && construct.expanded() ) {
     
    9191                        }
    9292
    9393                        // Note that we can't use :focusable due to a jQuery UI issue. See: https://github.com/jquery/jquery-ui/pull/1583
    94                         focusContainer.find( 'input, select, textarea, button, object, a[href], [tabindex]' ).filter( ':visible' ).first().focus();
     94                        focusElement = focusContainer.find( 'input, select, textarea, button' ).filter( ':visible' ).first();
     95                        // Focus on objects, links and other element only if no form element/input was found
     96                        if ( 0 === focusElement.length ) {
     97                                focusElement = focusContainer.find( 'object, a[href], [tabindex]' ).filter( ':visible' ).first();
     98                        }
     99                        focusElement.focus();
     100
    95101                };
    96102                if ( params.completeCallback ) {
    97103                        completeCallback = params.completeCallback;