Skip to content

Commit 07f1e19

Browse files
authored
Merge pull request #5518 from Polymer/fix-className-bindings-master
Ensure `className` bindings work correctly when `ShadyDOM.noPatch` is…
2 parents 176c001 + 652fea9 commit 07f1e19

File tree

7 files changed

+1554
-1424
lines changed

7 files changed

+1554
-1424
lines changed

lib/legacy/polymer.dom.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ class DomApiNative {
4848
* @param {Node} node Node for which to create a Polymer.dom helper object.
4949
*/
5050
constructor(node) {
51+
if (window['ShadyDOM'] && window['ShadyDOM']['inUse']) {
52+
window['ShadyDOM']['patch'](node);
53+
}
5154
this.node = node;
5255
}
5356

@@ -441,7 +444,7 @@ if (window['ShadyDOM'] && window['ShadyDOM']['inUse'] && window['ShadyDOM']['noP
441444
]);
442445

443446
forwardProperties(DomApiNative.prototype, [
444-
'textContent', 'innerHTML'
447+
'textContent', 'innerHTML', 'className'
445448
]);
446449
}
447450

lib/mixins/property-effects.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,12 @@ function setupCompoundStorage(node, binding) {
727727
storage[target] = literals;
728728
// Configure properties with their literal parts
729729
if (binding.literal && binding.kind == 'property') {
730+
// Note, className needs style scoping so this needs wrapping.
731+
// We may also want to consider doing this for `textContent` and
732+
// `innerHTML`.
733+
if (target === 'className') {
734+
node = wrap(node);
735+
}
730736
node[target] = binding.literal;
731737
}
732738
}
@@ -1407,6 +1413,10 @@ export const PropertyEffects = dedupingMixin(superClass => {
14071413
// implement a whitelist of tag & property values that should never
14081414
// be reset (e.g. <input>.value && <select>.value)
14091415
if (value !== node[prop] || typeof value == 'object') {
1416+
// Note, className needs style scoping so this needs wrapping.
1417+
if (prop === 'className') {
1418+
node = /** @type {!Node} */(wrap(node));
1419+
}
14101420
node[prop] = value;
14111421
}
14121422
}

lib/utils/wrap.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
1919
* @type {function(Node):Node}
2020
*/
2121
export const wrap = (window['ShadyDOM'] && window['ShadyDOM']['noPatch'] && window['ShadyDOM']['wrap']) ?
22-
window['ShadyDOM']['wrap'] : (n) => n;
22+
window['ShadyDOM']['wrap'] :
23+
(window['ShadyDOM'] ? (n) => ShadyDOM['patch'](n) : (n) => n);
2324

0 commit comments

Comments
 (0)