Skip to content
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

[JSX] Desugar aria'foo to aria-foo for DOM elements #196

Closed
chenglou opened this issue Mar 5, 2018 · 17 comments
Closed

[JSX] Desugar aria'foo to aria-foo for DOM elements #196

chenglou opened this issue Mar 5, 2018 · 17 comments

Comments

@chenglou
Copy link
Member

chenglou commented Mar 5, 2018

Actual transformer's in the Reason repo.

@rafayepes
Copy link
Contributor

Also data'foo to data-foo?

@yawaramin
Copy link
Contributor

Yup, it should be a general transformation of foo'bar -> foo-bar.

@chenglou
Copy link
Member Author

I'm thinking maybe we can just use ariaFoo -> aria-foo and dataFoo -> data-foo. Again, this is on DOM elements only, so no confusion of e.g. accepting ariaFoo in a custom component prop and do things with it.

@yawaramin
Copy link
Contributor

Could DOM elements potentially not have camelCased attribute names?

@chenglou
Copy link
Member Author

We’d only be doing it for aria and data

@yawaramin
Copy link
Contributor

Oh, I was imagining it would be simpler to check for the foo'bar form and convert it directly into "foo-bar", am I missing something?

@chenglou
Copy link
Member Author

Either is simple enough. But are you saying that we might as well go with ' since it generalizes to e.g. svg'set (nonexistent prop) instead of just data'foo or aria'foo? Though those other kebab-cased props don't exist, unless someone's trying to pass a custom dom prop

@yawaramin
Copy link
Contributor

Exactly, we can fully support any potential kebab-cased prop names thanks to ', which is great since kebab-cased attribute names are valid HTML. This would bring JSX more in line with valid HTML.

@chenglou
Copy link
Member Author

My main nitpicky concern is that it's ugly and we don't want to encourage over-usage of ' in prop names in Reason. But since this seems to be the only way to enable custom props, then let's do it.

@yawaramin
Copy link
Contributor

I think real-world use will be minimal. Kebab-cased attrs are pretty rare (unless you're using Angular 1 or something). In practice this will be just a nice escape hatch, not a heavily-used feature.

@chenglou
Copy link
Member Author

It's mandatory for a11y because of aria

@yawaramin
Copy link
Contributor

yawaramin commented Mar 12, 2018

Ya, but that's usually a minority of all JSX attributes. I think we won't see too much kebab'attrs in practice even after accounting for ARIA.

@chenglou
Copy link
Member Author

Related: we might find a good aria-* solution anyway with rescript-lang/rescript#2614

@alex35mil
Copy link
Contributor

I dunno, this doesn't seem ugly to me:

screen shot 2018-03-14 at 15 56 40

But when camelCase is used for everything:

dataTestid
onClick

it seems inconsistent a bit.

@bloodyowl
Copy link
Contributor

how about not having to add a special syntax?

<div
  data={
    "name": "some string"
  }
  aria={
    "role": "button",
    "label": "Open in modal"
  }
/>

@chenglou
Copy link
Member Author

chenglou commented May 27, 2018

Fixed in 0.4.2 thanks to bs.deriving abstract: https://github.com/reasonml/reason-react/blob/master/HISTORY.md#042

I'll open another issue for data-*, though I tend to just let folks use cloneElement

@alex35mil
Copy link
Contributor

Please, desugar data-* too, otherwise it’s required to clone every control from standard components (like Button and other interactive elements) to make them findable in integration tests.

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

No branches or pull requests

5 participants