demo/scripts/dialog-polyfill.js
function() {
      // Find element with `autofocus` attribute, or fall back to the first form/tabindex control.
      var target = this.dialog_.querySelector('[autofocus]:not([disabled])');
      if (!target && this.dialog_.tabIndex >= 0) {
        target = this.dialog_;
      }
      if (!target) {
        // Note that this is 'any focusable area'. This list is probably not exhaustive, but the
        // alternative involves stepping through and trying to focus everything.
        var opts = ['button', 'input', 'keygen', 'select', 'textarea'];
        var query = opts.map(function(el) {
          return el + ':not([disabled])';
        });
        // TODO(samthor): tabindex values that are not numeric are not focusable.
        query.push('[tabindex]:not([disabled]):not([tabindex=""])');  // tabindex != "", not disabled
        target = this.dialog_.querySelector(query.join(', '));
      }
      safeBlur(document.activeElement);
      target && target.focus();
    }
function() {
      // Find element with `autofocus` attribute, or fall back to the first form/tabindex control.
      var target = this.dialog_.querySelector('[autofocus]:not([disabled])');
      if (!target && this.dialog_.tabIndex >= 0) {
        target = this.dialog_;
      }
      if (!target) {
        // Note that this is 'any focusable area'. This list is probably not exhaustive, but the
        // alternative involves stepping through and trying to focus everything.
        var opts = ['button', 'input', 'keygen', 'select', 'textarea'];
        var query = opts.map(function(el) {
          return el + ':not([disabled])';
        });
        // TODO(samthor): tabindex values that are not numeric are not focusable.
        query.push('[tabindex]:not([disabled]):not([tabindex=""])');  // tabindex != "", not disabled
        target = this.dialog_.querySelector(query.join(', '));
      }
      safeBlur(document.activeElement);
      target && target.focus();
    }
function ( ) { // Find element with `autofocus` attribute, or fall back to the first form/tabindex control. var target = this . dialog_ . querySelector ( '[autofocus]:not([disabled])' ) ; if ( ! target && this . dialog_ . tabIndex >= 0 ) { target = this . dialog_ ; } if ( ! target ) { // Note that this is 'any focusable area'. This list is probably not exhaustive, but the // alternative involves stepping through and trying to focus everything. var opts = [ 'button' , 'input' , 'keygen' , 'select' , 'textarea' ] ; var query = opts . map ( function ( el ) { return el + ':not([disabled])' ; } ) ; // TODO(samthor): tabindex values that are not numeric are not focusable. query . push ( '[tabindex]:not([disabled]):not([tabindex=""])' ) ; // tabindex != "", not disabled target = this . dialog_ . querySelector ( query . join ( ', ' ) ) ; } safeBlur ( document . activeElement ) ; target && target . focus ( ) ; }
Focuses on the first focusable element within the dialog. This will always blur the current
focus, even if nothing within the dialog is found.
Focuses on the first focusable element within the dialog . This will always blur the current focus even if nothing within the dialog is found .