Skip to content

Allow jsx to write tags with bracket, instead of dot, notation. #1240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

actionnick
Copy link

This will allow for hyphenated tags in the future as something like
React.DOM["font-face"](content, mountNode)
instead of the invalid
React.DOM.font-face.(content, mountNode)
Many SVG tags have hyphenated tags so this would be a good thing to have.

This will allow for hyphenated tags in the future as something like
`React.DOM["font-face"](content, mountNode)`
instead of the invalid
`React.DOM.font-face.(content, mountNode)`
Many SVG tags have hyphenated tags so this would be a good thing to have.
@sophiebits
Copy link
Collaborator

Would be nice to share logic with quoteAttrName in xjs.js.

);
var tagOpening;
if (isFallbackTag) {
tagOpening = jsxObjIdent + '["' + (nameObject.name) + '"]' + '('
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this will break closure compiler minification. I think this would be a good idea if we could detect if it is not a valid JS identifier (ie. contains -) and use this only for invalid identifiers

Also centralize validity logic in xjs.js.
@actionnick
Copy link
Author

@spicyj How does this look?

if (isValidIdentifier(nameObject.name)) {
tagOpening = jsxObjIdent + '.' + (nameObject.name);
} else {
tagOpening = jsxObjIdent + '["' + (nameObject.name) + '"]';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe '[' + JSON.stringify(nameObject.name) + ']' here?

@sophiebits
Copy link
Collaborator

Looks pretty reasonable. I'll let @jeffmo review and merge.

@syranide
Copy link
Contributor

Going by how everything HTML-related is camelCased in JavaScript rather than hyphenated, doesn't it simply make more sense to call it fontFace? Seeing as we can only apply it to HTML/namespaced tags.

@actionnick
Copy link
Author

@syranide SVG spec defines a few tags that are hyphenated such as this one.

@syranide
Copy link
Contributor

@nschaubeck Right, but lowercase+hyphens is the HTML/markup naming convention, the general naming convention for HTML-related stuff in JavaScript is camelCased like all the official HTML APIs are.

@actionnick
Copy link
Author

@syranide So are you saying that JSX shouldn't support hyphenated tags? Or are you saying that it should supper camelCased version of hyphenated tags? Do those have to be mutually exclusive? JSX isn't a standard JS HTML API, it's an intermediary markup of sorts, so it makes sense to have this support to me.

@syranide
Copy link
Contributor

@nschaubeck My point of view (I'm not an official dev) would be that it might make sense for component-name to translate to componentName. The style-object supports that notation (I think?), but then again, HTML5 which would be the best guide to follow, the new data- attributes do not support it, data-key-name is accessed as keyName in JS. They even explicitly disallow ambiguity as data-keyName is accessed as keyname.

Personally I see two big issues:

  1. component-name and ComponentName are identical, it introduces a stylistic preference to something that doesn't need it/shouldn't have it.
  2. It's very weird that component becomes component, but component-name become ComponentName.

Is it weird to separate from the standard? Kind of, but we already have and JSX is not HTML, it's JavaScript and it's just sugar. So in many ways it makes sense (to me) for the notation to be JS-style (nodeName) as opposed to HTML-style (node-name), and not to deviate from that and open up the possibility to choose.

Side-note, the data--attribute in React does expect data-key-name right? (@zpao, @spicyj) Although that is not necessarily a concious decision.

@sophiebits
Copy link
Collaborator

Closing in favor of #1539 which does the same thing and is a little cleaner -- thanks for sending this in though!

@sophiebits sophiebits closed this May 23, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants