Skip to content

Commit

Permalink
Correct contentEditable code in Clear atom
Browse files Browse the repository at this point in the history
The clear atom would previously leave a single whitespace when clearing
contenteditable elements due to a limitation in firefox. This CL
makes it so that the whitespace is only left for firefox browsers.

Additionally, contenteditable elements previously did not unfocus after
clearing, which does not follow the W3C spec for clearing elements.
This changelist adds unfocusing code to run after a contenteditable
element is cleared.

Lastly, additional blur events would fire if the element to be cleared
had both a value and was contenteditable (eg a text input element with
a starting value and had its contenteditable attribute set to true).
This changelist corrects this by appending the contentEditable clause
to the end of the if-else chain.

Signed-off-by: Alexei Barantsev <barancev@gmail.com>
  • Loading branch information
Julian Kung authored and barancev committed Sep 20, 2019
1 parent 8264e39 commit f05ebbf
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions javascript/atoms/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,18 @@ bot.action.clear = function(element) {
// current value or not
bot.action.LegacyDevice_.focusOnElement(element);
element.value = '';
}

if (bot.dom.isContentEditable(element)) {
} else if (bot.dom.isContentEditable(element)) {
// A single space is required, if you put empty string here you'll not be
// able to interact with this element anymore in Firefox.
bot.action.LegacyDevice_.focusOnElement(element);
element.innerHTML = ' ';
element.innerHTML = goog.userAgent.GECKO ? ' ' : '';
var body = bot.getDocument().body;
if (body) {
bot.action.LegacyDevice_.focusOnElement(body);
} else {
throw new bot.Error(bot.ErrorCode.UNKNOWN_ERROR,
'Cannot unfocus element after clearing.');
}
// contentEditable does not generate onchange event.
}
};
Expand Down

0 comments on commit f05ebbf

Please sign in to comment.