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

class & className issue when wrapping defnc component with pure react component #45

Closed
orestis opened this issue Apr 3, 2019 · 3 comments

Comments

@orestis
Copy link
Member

orestis commented Apr 3, 2019

Hi again :)

I just ran into another issue with class & className (based on hx 0.4):

At various places, I'm wrapping some of my defnc components with react-bootstrap "Collapse" components.

The bootstrap collapse component will pass in an extra "className" attribute to my component, which I have to stick to my top-level div.

Example:

;; ... snip ... wrapping looks like:
[bootstrap/Collapse {:in is-current}
    children]

;; and component declaration looks like:

(defnc MyMenu [{:keys [class] :as props}]
  [:div {:class class}
    ;; snip
    ])

It looks like that MyMenu receives className but not class.

I haven't had time to look at the hx code to see where this could be taken care of, but I think that given that I can use MyMenu from other places by using class, it should be usable also with native React components wrapping it.

Thoughts?

@lilactown
Copy link
Collaborator

That is strange. The processing for className -> class happens in the defnc macro, so I'm not sure why calling it in different ways would effect it.

I don't quite understand how you're wrapping it. Is it that children ends up being MyMenu?

@lilactown
Copy link
Collaborator

lilactown commented Apr 6, 2019

Like the only notable thing I can see is that I'm guessing Collapse uses cloneElement...

EDIT: Yep, it uses cloneElement. Could that be why?

lilactown added a commit that referenced this issue Apr 6, 2019
@lilactown
Copy link
Collaborator

It's because the props-rewriting of className to class only happens in hiccup parsing. So cloneElement was bypassing that.

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

2 participants