Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Focus the dialog by default #6

Merged
merged 1 commit into from
Feb 9, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@svachon-ayogo This would also need to be added to our reset stylesheet for Chrome (which supports dialog natively and doesn't get these styles injected)

'}',
'',
'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