syntax icon indicating copy to clipboard operation
syntax copied to clipboard

[Feature request] dash in jsx

Open amiralies opened this issue 5 years ago • 8 comments

Although i'm not sure if it's possible but It would be nice to have dash support in jsx elements and jsx props: Use cases:

elements:

<amp-img></amp-img> // amp web components

props:

<div data-testid="foo" /> // data-* props

amiralies avatar Oct 31 '20 21:10 amiralies

I guess that doable for elements, but the current way attributes are defined in ReasonReact would prevent custom props from being used as-is

bloodyowl avatar Nov 01 '20 17:11 bloodyowl

I'm not 100% sure if this is a good idea. It would definitely add yet another concept to jsx and is pretty inconsistent with punning:

// You can't do this
let data-testid = "foo"
<div data-testid />

data-* attributes aren't that common, would it be worth introducing extra rules?

IwanKaramazow avatar Nov 08 '20 19:11 IwanKaramazow

I think they should be supported at some point.

amiralies avatar Nov 08 '20 22:11 amiralies

@amiralies In the meantime for data attributes, you can do the following:

React.cloneElement(<div />, {"data-testid": "foo"})

bloodyowl avatar Nov 10 '20 23:11 bloodyowl

This would be possible with escaped prop names, right? <div \"data-testid"="foo" />

Although this still wouldn't compile because the React div element doesn't have data-testid in its signature. That may be a separate issue.

johnridesabike avatar Dec 04 '20 22:12 johnridesabike

This will most likely be solved in a future react-ppx update. Goal is to allow easy definition of data and aria attributes, and generally change the way how dom elements are being type checked.

ryyppy avatar Jan 03 '21 10:01 ryyppy

This would be possible with escaped prop names, right? <div \"data-testid"="foo" />

Fwiw, it's equally doable for the tags: <\"my-tag" />

hoichi avatar Oct 20 '21 10:10 hoichi

any update this?

thomaszdxsn avatar Nov 04 '21 12:11 thomaszdxsn

The rescript-lang/syntax repo is obsolete and will be archived soon. If this issue is still relevant, please reopen in the compiler repo (https://github.com/rescript-lang/rescript-compiler) or comment here to ask for it to be moved. Thank you for your contributions.

stale[bot] avatar May 28 '23 19:05 stale[bot]