Skip to content

Commit

Permalink
Merge pull request #5125 from Polymer/auto-detect-attribute-capitaliz…
Browse files Browse the repository at this point in the history
…ation

Automatically detect capitalized HTML attributes
  • Loading branch information
kevinpschaaf authored Mar 13, 2018
2 parents 83b13fa + 0573d48 commit 5422bef
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/mixins/property-effects.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
READ_ONLY: '__readOnly'
};

/** @const {string} */
const capitalAttributeRegex = /[A-Z]/;

/**
* @typedef {{
* name: (string | undefined),
Expand Down Expand Up @@ -2535,7 +2538,12 @@
// Attribute or property
let origName = name;
let kind = 'property';
if (name[name.length-1] == '$') {
// The only way we see a capital letter here is if the attr has
// a capital letter in it per spec. In this case, to make sure
// this binding works, we go ahead and make the binding to the attribute.
if (capitalAttributeRegex.test(name)) {
kind = 'attribute';
} else if (name[name.length-1] == '$') {
name = name.slice(0, -1);
kind = 'attribute';
}
Expand Down
22 changes: 22 additions & 0 deletions test/unit/property-effects-elements.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<link rel="import" href="../../polymer.html">

<dom-module id="x-basic">
<template>
<div id="boundChild"
Expand Down Expand Up @@ -1062,3 +1064,23 @@
}
customElements.define(SubObserverElement.is, SubObserverElement);
</script>

<dom-module id="svg-element">
<template>
<svg id="svg" viewBox="[[value]]"></svg>
</template>
<script>
class SVGElement extends Polymer.Element {
static get is() { return 'svg-element'; }
static get properties() {
return {
value: {
type: String,
value: '0 0 50 50'
}
};
}
}
customElements.define(SVGElement.is, SVGElement);
</script>
</dom-module>
17 changes: 17 additions & 0 deletions test/unit/property-effects.html
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,23 @@
assert.equal(el.__observerCalled, 1);
});
});

suite('automated attribute capitalization detection', function() {
let el;

setup(function() {
el = document.createElement('svg-element');
document.body.appendChild(el);
});

teardown(function() {
document.body.removeChild(el);
});

test('can handle capitalized HTML attribute', function() {
assert.equal(el.$.svg.getAttribute('viewBox'), el.value);
});
});
});

suite('computed bindings with dynamic functions', function() {
Expand Down

0 comments on commit 5422bef

Please sign in to comment.