-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Workaround bindings to textarea.placeholder in IE #5577
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,49 @@ const templateExtensions = { | |
'dom-if': true, | ||
'dom-repeat': true | ||
}; | ||
|
||
let placeholderBugDetect = false; | ||
let placeholderBug = false; | ||
|
||
function hasPlaceholderBug() { | ||
if (!placeholderBugDetect) { | ||
const t = document.createElement('textarea'); | ||
t.placeholder = 'a'; | ||
placeholderBug = t.placeholder === t.textContent; | ||
} | ||
return placeholderBug; | ||
} | ||
|
||
/** | ||
* Some browsers have a bug with textarea, where placeholder text is copied as | ||
* a textnode child of the textarea. | ||
* | ||
* If the placeholder is a binding, this can break template stamping in two | ||
* ways. | ||
* | ||
* One issue is that when the `placeholder` binding is removed, the textnode | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
* child of the textarea is deleted, and the template info tries to bind into | ||
* that node. | ||
* | ||
* When `legacyOptimizations` is enabled, the node is removed from the textarea | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When the template is stamped and the |
||
* when the `placeholder` binding is processed, leaving an "undefined" cell in | ||
* the binding metadata object. | ||
* | ||
* When `legacyOptimizations` is disabled, the template is cloned before | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When |
||
* processing, and has an extra binding to the textContent of the text node | ||
* child of the textarea. This at best is an extra binding to process that has | ||
* no useful effect, and at worst throws exceptions trying to update the text | ||
* node. | ||
* | ||
* @param {!Node} node Check node for placeholder bug | ||
* @return {boolean} True if placeholder is bugged | ||
*/ | ||
function shouldFixPlaceholder(node) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggest refactoring to |
||
return hasPlaceholderBug() | ||
&& node.localName === 'textarea' && node.placeholder | ||
&& node.placeholder === node.textContent; | ||
} | ||
|
||
function wrapTemplateExtension(node) { | ||
let is = node.getAttribute('is'); | ||
if (is && templateExtensions[is]) { | ||
|
@@ -251,6 +294,9 @@ export const TemplateStamp = dedupingMixin( | |
// For ShadyDom optimization, indicating there is an insertion point | ||
templateInfo.hasInsertionPoint = true; | ||
} | ||
if (shouldFixPlaceholder(node)) { | ||
node.textContent = null; | ||
} | ||
if (element.firstChild) { | ||
this._parseTemplateChildNodes(element, templateInfo, nodeInfo); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
placeholderBugDetect = true