-
Notifications
You must be signed in to change notification settings - Fork 349
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
Allow data-* in DOM elements #230
Comments
It would be very unfortunate b/c I will need to clone all interactive elements in components library to make them findable in integration tests. |
One more case I faced today: I'm almost finished bindings to |
maybe having a little abstraction could be enough? let withDataAttributes = (~data, element) =>
ReasonReact.cloneElement(
element,
~props=Obj.magic(Js.Dict.fromList(data)),
[||],
);
let div =
withDataAttributes(
~data=[("data-foo", "bar"), ("data-bar", "baz")],
<div />,
);
ReactDOMRe.renderToElementWithId(div, "preview"); |
We make heavy use of Will something #196 (comment) be possible? |
I have the same issue @rafayepes describes |
looked a bit at what we could do right now and bumped into a few issues that'd make it non-trivial. I tried to wrap the Another way would be to allow passing a transformer function to a field in And a possible third alternative I see would be to allow an "unsafe spread" directly in JSX: <div
...{"data-foo": "bar"}
/> |
Could you not add an unsafe option for edgecases? |
this would require some changes on bs.deriving abstract or FFI propagation AFAIK |
Is there at present a recommended solution for using data attributes? |
Ran into the problem with cypress needing custom data-* attributes for e2e testing. |
Is there a reason not to add something like
|
Guessing not zero cost. Workaround from @yawaramin works pretty well until there’s official solution: module WithTestId = {
[@react.component]
let make = (~id: string, ~children) =>
ReasonReact.cloneElement(children, ~props={"data-test-id": id}, [||]);
};
<WithTestId id="foo"> <button /> </WithTestId> |
Hey @alexfedoseev Would you mind creating a PR and adding that to the docs? This is an awesome workaround for now. Thank you! |
Hey everyone, we've added an example here: https://reasonml.github.io/reason-react/docs/en/adding-data-props |
I was thinking of making its own abstraction to Spread component? @peterpme for instance like special |
Hey @heygema open up a PR and we can take a look 😄 |
aria-foo
is supported throughariaFoo
, because we exhaustively list all the aria options.data-*
is dynamic. I think it's fine to use cloneElement to add them as an escape hatch.The text was updated successfully, but these errors were encountered: