8000 feat: add triggerElementProps to allow passing of props to trigger element by MattBodey · Pull Request #147 · glennflanagan/react-collapsible · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: add triggerElementProps to allow passing of props to trigger element #147

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

Merged
merged 1 commit into from
Feb 26, 2020
Merged

feat: add triggerElementProps to allow passing of props to trigger element #147

merged 1 commit into from
Feb 26, 2020

Conversation

MattBodey
Copy link
Contributor

This PR fixes #146 by allowing the user to pass a new prop to the component.

@karltaylor
Copy link
Collaborator
karltaylor commented Feb 26, 2020

Thanks Matt, this works great. CC @glennflanagan

What do you think about throwing a warning/error if a user tries to pass className to triggerElementProps?

If they do, the collapsible styling + functionality will break because

className={triggerClassString.trim()}

        <TriggerElement
          className={triggerClassString.trim()} // - this will be overwritten

We could do something like this in mount?

componentDidMount() {
  const { triggerElementProps } = this.props
  if (triggerElementProps && triggerElementProps.className) {
    console.warn('Cannot pass className to triggerElementProps')
   // or explicitly, (People using CRA would have a visual error if they're using the overlay)
   throw new Error('Cannot pass className to triggerElementProps')
  }
}

@glennflanagan
Copy link
Owner

@karltaylor if the className is required then we should spread the className into the triggerElementProps object to ensure it's there, or even better still, merge the two classNames

@karltaylor
Copy link
Collaborator

We have the prop triggerClassName already though so we would be getting a prop from two different locations so it might start to get a bit complicated

@karltaylor
Copy link
Collaborator

To be honest,

We already do this here:

<ContentContainerElement className={parentClassString.trim()} {...this.props.containerElementProps}>

I guess we can leave it to the user to understand not to pass the className into this prop as it will break stuff?

@karltaylor
Copy link
Collaborator

I'm happy to merge 🎉🚀

@MattBodey thanks for creating an itch to work on this over the weekend 👍 😅

@glennflanagan
Copy link
Owner

Agreed, this is something that can be avoided by dev config so we don't need to overcomplicate the code even more

@karltaylor karltaylor merged commit b5f5128 into glennflanagan:develop Feb 26, 2020
@MattBodey
Copy link
Contributor Author

Thanks!

I think that merging the className would be a good idea, though I hope that by the time someone is injecting custom props they understand what they are doing somewhat 😄

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

Successfully merging this pull request may close these issues.

Be able to set custom properties on trigger element
3 participants
0