Permalink
Browse files

When <Enter> is pressed on Dialog, ignore if tag is 'A' (anchor tag),…

… as the user is trying to follow a link.

R=ssaviano,nicksantos
DELTA=29  (17 added, 0 deleted, 12 changed)


Revision created by MOE tool push_codebase.
MOE_MIGRATION=5777


git-svn-id: http://closure-library.googlecode.com/svn/trunk@2279 0b95b8e8-c90f-11de-9d4f-f947ee5921c8
  • Loading branch information...
bobbrose@google.com
bobbrose@google.com committed Nov 7, 2012
1 parent 9e6f04f commit 33354d3b6f82245cb11d002095b9b61f38ca06e4
Showing with 28 additions and 12 deletions.
  1. +1 −1 closure/goog/deps.js
  2. +5 −3 closure/goog/ui/dialog.js
  3. +22 −8 closure/goog/ui/dialog_test.html
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -35,7 +35,9 @@ goog.require('goog.dom');
goog.require('goog.dom.NodeType');
goog.require('goog.dom.TagName');
goog.require('goog.dom.a11y');
+goog.require('goog.dom.a11y.Role');
goog.require('goog.dom.classes');
+goog.require('goog.events');
goog.require('goog.events.Event');
goog.require('goog.events.EventType');
goog.require('goog.events.KeyCodes');
@@ -1019,10 +1021,10 @@ goog.ui.Dialog.prototype.onKey_ = function(e) {
var defaultKey = buttonSet.getDefault();
var defaultButton = defaultKey && buttonSet.getButton(defaultKey);
- // Users may expect to hit enter on a TEXTAREA or a SELECT element.
+ // Users may expect to hit enter on a TEXTAREA, SELECT or an A element.
var isSpecialFormElement =
- (target.tagName == 'TEXTAREA' || target.tagName == 'SELECT') &&
- !target.disabled;
+ (target.tagName == 'TEXTAREA' || target.tagName == 'SELECT' ||
+ target.tagName == 'A') && !target.disabled;
if (defaultButton && !defaultButton.disabled && !isSpecialFormElement) {
key = defaultKey;
@@ -135,23 +135,37 @@
}
function testEnterKeyDoesNothingOnSpecialFormElements() {
- dialog.setContent('<textarea>Hello dialog</textarea>');
- var textarea = dialog.getContentElement().
- getElementsByTagName('TEXTAREA')[0];
+ checkEnterKeyDoesNothingOnSpecialFormElement(
+ '<textarea>Hello dialog</textarea>',
+ 'TEXTAREA');
+
+ checkEnterKeyDoesNothingOnSpecialFormElement(
+ '<Select>Selection</select>',
+ 'SELECT');
+
+ checkEnterKeyDoesNothingOnSpecialFormElement(
+ '<a href="http://google.com">Hello dialog</a>',
+ 'A');
+ }
+
+ function checkEnterKeyDoesNothingOnSpecialFormElement(content, tagName) {
+ dialog.setContent(content);
+ var formElement = dialog.getContentElement().
+ getElementsByTagName(tagName)[0];
var wasCalled = false;
var callRecorder = function() {
wasCalled = true;
};
goog.events.listen(dialog, goog.ui.Dialog.EventType.SELECT, callRecorder);
- // Enter does not fire on the enabled textarea.
- goog.testing.events.fireKeySequence(textarea,
+ // Enter does not fire on the enabled form element.
+ goog.testing.events.fireKeySequence(formElement,
goog.events.KeyCodes.ENTER);
assertFalse(wasCalled);
- // Enter fires on the disabled textarea.
- textarea.disabled = true;
- goog.testing.events.fireKeySequence(textarea,
+ // Enter fires on the disabled form element.
+ formElement.disabled = true;
+ goog.testing.events.fireKeySequence(formElement,
goog.events.KeyCodes.ENTER);
assertTrue(wasCalled);
}

0 comments on commit 33354d3

Please sign in to comment.