Skip to content

Commit

Permalink
WIP: make <a> tags SVG elements when they have xlink:href.
Browse files Browse the repository at this point in the history
Needs a test case.
  • Loading branch information
Emily Stark committed Jun 20, 2014
1 parent b31629d commit e6fb17e
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion packages/ui/render.js
Expand Up @@ -347,7 +347,21 @@ var materialize = function (node, parent, before, parentComponent) {
} else if (node instanceof HTML.Tag) {
var tagName = node.tagName;
var elem;
if (HTML.isKnownSVGElement(tagName) && document.createElementNS) {
if ((HTML.isKnownSVGElement(tagName) ||
// We generally aren't able to detect SVG <a> elements because

This comment has been minimized.

Copy link
@avital

avital Jun 20, 2014

Contributor

Can we not inline this? Instead add a utility function isSVGAElement or something.

This comment has been minimized.

Copy link
@avital

avital Jun 20, 2014

Contributor

isSvgAElement maybe? this decision doesn't actually matter

This comment has been minimized.

Copy link
@estark37

estark37 Jun 23, 2014

Contributor

While taking your suggestion to inline this check, I noticed that it's completely buggy (see the paren after ["xlink:href"]), which explains why I wasn't able to find a test case!

// if "A" were in our list of known svg element names, then all
// <a> nodes would be created using
// `document.createElementNS`. But in the special case of <a
// xlink:href="...">, we can at least detect that attribute and
// create an SVG <a> tag in that case.
//
// However, we still have a general problem of knowing when to
// use document.createElementNS and when to use
// document.createElement; for example, font tags will always
// be created as SVG elements which can cause other
// problems. #1977
(tagName === "A" && node.attrs["xlink:href"]) !== undefined) &&

This comment has been minimized.

Copy link
@avital

avital Jun 20, 2014

Contributor

Is node.attrs ever null or undefined? We should check regardless.

document.createElementNS) {
elem = document.createElementNS('http://www.w3.org/2000/svg', tagName);
} else {
elem = document.createElement(node.tagName);
Expand Down

0 comments on commit e6fb17e

Please sign in to comment.