Skip to content

Commit

Permalink
Merge pull request #5518 from Polymer/fix-className-bindings-master
Browse files Browse the repository at this point in the history
Ensure `className` bindings work correctly when `ShadyDOM.noPatch` is…
  • Loading branch information
dfreedm authored Apr 20, 2019
2 parents 176c001 + 652fea9 commit 07f1e19
Show file tree
Hide file tree
Showing 7 changed files with 1,554 additions and 1,424 deletions.
5 changes: 4 additions & 1 deletion lib/legacy/polymer.dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ class DomApiNative {
* @param {Node} node Node for which to create a Polymer.dom helper object.
*/
constructor(node) {
if (window['ShadyDOM'] && window['ShadyDOM']['inUse']) {
window['ShadyDOM']['patch'](node);
}
this.node = node;
}

Expand Down Expand Up @@ -441,7 +444,7 @@ if (window['ShadyDOM'] && window['ShadyDOM']['inUse'] && window['ShadyDOM']['noP
]);

forwardProperties(DomApiNative.prototype, [
'textContent', 'innerHTML'
'textContent', 'innerHTML', 'className'
]);
}

Expand Down
10 changes: 10 additions & 0 deletions lib/mixins/property-effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,12 @@ function setupCompoundStorage(node, binding) {
storage[target] = literals;
// Configure properties with their literal parts
if (binding.literal && binding.kind == 'property') {
// Note, className needs style scoping so this needs wrapping.
// We may also want to consider doing this for `textContent` and
// `innerHTML`.
if (target === 'className') {
node = wrap(node);
}
node[target] = binding.literal;
}
}
Expand Down Expand Up @@ -1407,6 +1413,10 @@ export const PropertyEffects = dedupingMixin(superClass => {
// implement a whitelist of tag & property values that should never
// be reset (e.g. <input>.value && <select>.value)
if (value !== node[prop] || typeof value == 'object') {
// Note, className needs style scoping so this needs wrapping.
if (prop === 'className') {
node = /** @type {!Node} */(wrap(node));
}
node[prop] = value;
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/utils/wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
* @type {function(Node):Node}
*/
export const wrap = (window['ShadyDOM'] && window['ShadyDOM']['noPatch'] && window['ShadyDOM']['wrap']) ?
window['ShadyDOM']['wrap'] : (n) => n;
window['ShadyDOM']['wrap'] :
(window['ShadyDOM'] ? (n) => ShadyDOM['patch'](n) : (n) => n);

Loading

0 comments on commit 07f1e19

Please sign in to comment.