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

Add support for htmlAttributes (or className) parameter. #210

Closed
jovnas opened this Issue Jan 15, 2016 · 3 comments

Comments

Projects
None yet
2 participants
@jovnas
Copy link
Contributor

jovnas commented Jan 15, 2016

Unless there already is a way to add classes to the containing div, I would suggest adding support for the (pretty common) htmlAttributes parameter.

@Html.React("MyComponent", new { data = Model }, htmlTag: "div", containerId: "my-container", htmlAttributes: new { @class = "my-class-needed-on-container" })

I can see this could be problematic if one should try to add an id using the htmlAttributes even if containerId is provided.

An alternative solution is to add a specific parameter className that takes a string of classes to add to the container. This is probably the most "sane" way to do it, since you probably do not want to allow other attributes than class to a React-container.

@Html.React("MyComponent", new { data = Model }, htmlTag: "div", containerId: "my-container", className: "my-class-needed-on-container" )
@Daniel15

This comment has been minimized.

Copy link
Member

Daniel15 commented Jan 16, 2016

Feel free to send a pull request adding this if you want :)

Are there any use cases that can be solved by this that can't be solved simply by adding the attributes onto the React component instead?

@jovnas

This comment has been minimized.

Copy link
Contributor

jovnas commented Jan 16, 2016

My current problem is the use of child selectors in css. Since React.NET "adds an extra element" around the component, the child selector does not work unless I add another child level in the css. I could of course rewrite my other "components" to include the extra child level in the HTML also, but adding a class to the container seems like the easier path. (If you're lazy like me... ;-) )

I will try to submit a pull request. It's my first ever, so I hope I get it right! :-)

@Daniel15

This comment has been minimized.

Copy link
Member

Daniel15 commented Jan 24, 2016

Added in #211, thanks @jovnas

@Daniel15 Daniel15 closed this Jan 24, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment