Skip to content

Commit

Permalink
support the other special prop (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
nathancahill authored and developit committed Apr 30, 2017
1 parent 8767d17 commit a111d56
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/vhtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import emptyTags from './empty-tags';
// escape an attribute
let esc = str => String(str).replace(/[&<>"']/g, s=>`&${map[s]};`);
let map = {'&':'amp','<':'lt','>':'gt','"':'quot',"'":'apos'};
let DOMAttributeNames = {
className: 'class',
htmlFor: 'for'
};

let sanitized = {};

Expand All @@ -23,7 +27,7 @@ export default function h(name, attrs) {
let s = `<${name}`;
if (attrs) for (let i in attrs) {
if (attrs[i]!==false && attrs[i]!=null) {
s += ` ${i === 'className' ? 'class' : esc(i)}="${esc(attrs[i])}"`;
s += ` ${DOMAttributeNames[i] ? DOMAttributeNames[i] : esc(i)}="${esc(attrs[i])}"`;
}
}

Expand Down
6 changes: 3 additions & 3 deletions test/vhtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,11 @@ describe('vhtml', () => {
);
});

it('should handle className as class', () => {
it('should handle special prop names', () => {
expect(
<div className="my-class" />
<div className="my-class" htmlFor="id" />
).to.equal(
'<div class="my-class"></div>'
'<div class="my-class" for="id"></div>'
);
});
});

0 comments on commit a111d56

Please sign in to comment.