Index: chrome/browser/resources/options/inline_editable_list.js |
diff --git a/chrome/browser/resources/options/inline_editable_list.js b/chrome/browser/resources/options/inline_editable_list.js |
index b762a1d6d4a1d9b4c850d1b69ad66f59e648e21c..01aafedc26634652eea25cf0374a563b75ad123d 100644 |
--- a/chrome/browser/resources/options/inline_editable_list.js |
+++ b/chrome/browser/resources/options/inline_editable_list.js |
@@ -151,6 +151,9 @@ cr.define('options', function() { |
} else { |
if (!this.editCancelled_ && this.hasBeenEdited && |
this.currentInputIsValid) { |
+ if (this.isPlaceholder) |
+ this.parentNode.focusPlaceholder = true; |
+ |
this.updateStaticValues_(); |
cr.dispatchSimpleEvent(this, 'commitedit', true); |
} else { |
@@ -242,7 +245,19 @@ cr.define('options', function() { |
if (!this.isPlaceholder) { |
inputEl.setAttribute('displaymode', 'edit'); |
inputEl.staticVersion = textEl; |
+ } else { |
+ // At this point |this| is not attached to the parent list yet, so give |
+ // a short timeout in order for the attachment to occur. |
+ var self = this; |
+ window.setTimeout(function() { |
+ var list = self.parentNode; |
+ if (list && list.focusPlaceholder) { |
+ list.focusPlaceholder = false; |
+ inputEl.focus(); |
+ } |
+ }, 50); |
} |
+ |
inputEl.addEventListener('focus', this.handleFocus_.bind(this)); |
container.appendChild(inputEl); |
this.editFields_.push(inputEl); |
@@ -261,6 +276,7 @@ cr.define('options', function() { |
var staticLabel = editFields[i].staticVersion; |
if (!staticLabel && !this.isPlaceholder) |
continue; |
+ |
if (editFields[i].tagName == 'INPUT') { |
editFields[i].value = |
this.isPlaceholder ? '' : staticLabel.textContent; |
@@ -283,6 +299,7 @@ cr.define('options', function() { |
var staticLabel = editFields[i].staticVersion; |
if (!staticLabel) |
continue; |
+ |
if (editFields[i].tagName == 'INPUT') |
staticLabel.textContent = editFields[i].value; |
// Add more tag types here as new createEditable* methods are added. |
@@ -361,6 +378,12 @@ cr.define('options', function() { |
InlineEditableItemList.prototype = { |
__proto__: DeletableItemList.prototype, |
+ /** |
+ * Focuses the input element of the placeholder if true. |
+ * @type {boolean} |
+ */ |
+ focusPlaceholder: false, |
+ |
/** @inheritDoc */ |
decorate: function() { |
DeletableItemList.prototype.decorate.call(this); |