Skip to content
This repository has been archived by the owner on Jan 22, 2024. It is now read-only.

Commit

Permalink
Don't attempt to focus a disabled button. This causes the modal dialog
Browse files Browse the repository at this point in the history
to lose focus -- and the button isn't focused either.

Tested:
Manually on Chrome + unit test

R=nicksantos
DELTA=14 (13 added, 0 deleted, 1 changed)


Revision created by MOE tool push_codebase.
MOE_MIGRATION=6091


git-svn-id: http://closure-library.googlecode.com/svn/trunk@2422 0b95b8e8-c90f-11de-9d4f-f947ee5921c8
  • Loading branch information
mariakhomenko@google.com committed Jan 8, 2013
1 parent 22f7e9e commit 061c954
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion closure/goog/ui/dialog.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ goog.ui.Dialog.prototype.focus = function() {
var doc = this.getDomHelper().getDocument(); var doc = this.getDomHelper().getDocument();
var buttons = this.buttonEl_.getElementsByTagName('button'); var buttons = this.buttonEl_.getElementsByTagName('button');
for (var i = 0, button; button = buttons[i]; i++) { for (var i = 0, button; button = buttons[i]; i++) {
if (button.name == defaultButton) { if (button.name == defaultButton && !button.disabled) {
try { try {
// Reopening a dialog can cause focusing the button to fail in // Reopening a dialog can cause focusing the button to fail in
// WebKit and Opera. Shift the focus to a temporary <input> // WebKit and Opera. Shift the focus to a temporary <input>
Expand Down
13 changes: 13 additions & 0 deletions closure/goog/ui/dialog_test.html
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@
assertEquals(2, focusCounter); assertEquals(2, focusCounter);
} }


function testNoDisabledButtonFocus() {
dialog.setVisible(false);
var buttonEl =
dialog.getButtonSet().getButton(goog.ui.Dialog.DefaultButtonKeys.OK);
buttonEl.disabled = true;
var focused = false;
buttonEl.focus = function() {
focused = true;
}
dialog.setVisible(true);
assertFalse('Should not have called focus on disabled button', focused);
}

function testNoTitleClose() { function testNoTitleClose() {
assertTrue(goog.style.isElementShown(dialog.getTitleCloseElement())); assertTrue(goog.style.isElementShown(dialog.getTitleCloseElement()));
dialog.setHasTitleCloseButton(false); dialog.setHasTitleCloseButton(false);
Expand Down

0 comments on commit 061c954

Please sign in to comment.