Skip to content

Commit

Permalink
Merge pull request facebook#1590 from spicyj/svg-classname
Browse files Browse the repository at this point in the history
Handle className properly on SVG nodes
  • Loading branch information
zpao committed May 28, 2014
2 parents f230e0a + 37f61c4 commit 0ad8cfa
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/browser/ui/dom/HTMLDOMPropertyConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"use strict";

var DOMProperty = require('DOMProperty');
var ExecutionEnvironment = require('ExecutionEnvironment');

var MUST_USE_ATTRIBUTE = DOMProperty.injection.MUST_USE_ATTRIBUTE;
var MUST_USE_PROPERTY = DOMProperty.injection.MUST_USE_PROPERTY;
Expand All @@ -32,6 +33,20 @@ var HAS_POSITIVE_NUMERIC_VALUE =
var HAS_OVERLOADED_BOOLEAN_VALUE =
DOMProperty.injection.HAS_OVERLOADED_BOOLEAN_VALUE;

var hasSVG;
if (ExecutionEnvironment.canUseDOM) {
var implementation = document.implementation;
hasSVG = (
implementation &&
implementation.hasFeature &&
implementation.hasFeature(
'http://www.w3.org/TR/SVG11/feature#BasicStructure',
'1.1'
)
);
}


var HTMLDOMPropertyConfig = {
isCustomAttribute: RegExp.prototype.test.bind(
/^(data|aria)-[a-z_][a-z\d_.\-]*$/
Expand All @@ -55,7 +70,12 @@ var HTMLDOMPropertyConfig = {
cellSpacing: null,
charSet: MUST_USE_ATTRIBUTE,
checked: MUST_USE_PROPERTY | HAS_BOOLEAN_VALUE,
className: MUST_USE_PROPERTY,
// To set className on SVG elements, it's necessary to use .setAttribute;
// this works on HTML elements too in all browsers except IE8. Conveniently,
// IE8 doesn't support SVG and so we can simply use the attribute in
// browsers that support SVG and the property in browsers that don't,
// regardless of whether the element is HTML or SVG.
className: hasSVG ? MUST_USE_ATTRIBUTE : MUST_USE_PROPERTY,
cols: MUST_USE_ATTRIBUTE | HAS_POSITIVE_NUMERIC_VALUE,
colSpan: null,
content: null,
Expand Down

0 comments on commit 0ad8cfa

Please sign in to comment.