Skip to content

Commit

Permalink
Focus the dialog by default
Browse files Browse the repository at this point in the history
  • Loading branch information
dpogue committed Jan 17, 2017
1 parent 3ef2879 commit c441533
Showing 1 changed file with 9 additions and 31 deletions.
40 changes: 9 additions & 31 deletions dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,6 @@ angular.module('ayDialog', [])

var kZIndexMax = Math.pow(2, 31) - 1;

// Courtesy of AngularUI Bootstrap's $modal service
var FOCUS_SELECTOR = [
'a[href]',
'area[href]',
'input:not([disabled])',
'button:not([disabled])',
'select:not([disabled])',
'textarea:not([disabled])',
'keygen:not([disabled])',
'iframe',
'object',
'embed',
'[tabindex]:not([disabled]):not([tabindex=""])',
'[contenteditable=true]'
].join(',');


var DIALOG_STYLES = [
'[hidden] {',
Expand Down Expand Up @@ -75,6 +59,10 @@ angular.module('ayDialog', [])
' -webkit-overflow-scrolling: touch;',
'}',
'',
'dialog:focus {',
' outline: 0 none;',
'}',
'',
'dialog[open] {',
' visibility: visible;',
'}',
Expand Down Expand Up @@ -124,21 +112,6 @@ angular.module('ayDialog', [])
return;
}

var control = el.querySelector(FOCUS_SELECTOR);

if (control) {
if (immediate) {
control.focus();
return;
}

$window.setTimeout(function() {
control.focus();
}, 1);
el.focus();
return;
}

el.focus();
}

Expand Down Expand Up @@ -312,6 +285,11 @@ angular.module('ayDialog', [])
el.setAttribute('role', 'dialog');
}

// Ensure the dialog is focusable
if (!el.hasAttribute('tabindex')) {
el.tabIndex = -1;
}


if (('HTMLDialogElement' in $window) &&
(el instanceof $window.HTMLDialogElement))
Expand Down

0 comments on commit c441533

Please sign in to comment.