Skip to content

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

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
jovnas opened this issue Jan 15, 2016 · 3 comments
Closed

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

jovnas opened this issue Jan 15, 2016 · 3 comments

Comments

@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
Copy link
Member

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
Copy link
Contributor Author

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
Copy link
Member

Added in #211, thanks @jovnas

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

No branches or pull requests

2 participants