Skip to content

Add new param shouldForwardProps to allow the passing in of 'invalid' attributes - #2780

Closed
kenhkelly wants to merge 2 commits into
styled-components:masterfrom
kenhkelly:master
Closed

kenhkelly wants to merge 2 commits into
styled-components:masterfrom
kenhkelly:master

Conversation

@kenhkelly

Copy link
Copy Markdown

This PR came up because we were using v3 and were passing in what are being determined as invalid attributes. We upgrade for v4 to fix another styling issue and found out our analytics broke.

We use these attributes for our analytics tracking to have simple event listeners set up globally.

<button anclick="home_page_button" type="primary" class="buttonstyled__Button-sc-1t8li5e-0 YHsJf">HomePage</button>

The usage to achieve bring the attributes back is by simply adding shouldForwardProps to the styled component.

return <StyledButton
          anclick={anclick}
          anevent={anevent}
          atc={atc}
          btnsize={btnsize}
          btnwidth={btnwidth}
          disabled={disabled}
          id={id}
          onClick={this.onClick}
          type={type}
          ref={forwardedRef}
          shouldForwardProps
          {...this.props}
        >
          {children}
        </StyledButton>;

@quantizor

quantizor commented Oct 3, 2019 via email

Copy link
Copy Markdown
Contributor

@kenhkelly

Copy link
Copy Markdown
Author

Hind-sight, but we are a large e-commerce site and that would require a ton of refactor. That's why I made the one prop that is opt-in for us and for those that might also have something similar where white-listing of attributes is a stopper.

I’d highly recommend using data attributes for this, that’s what they’re intended for.
…
On Thu, Oct 3, 2019 at 10:22 AM Ken Kelly @.***> wrote: This PR came up because we were using v3 and were passing in what are being determined as invalid attributes. We upgrade for v4 to fix another styling issue and found out our analytics broke. We use these attributes for our analytics tracking to have simple event listeners set up globally. HomePage The usage to achieve bring the attributes back is by simply adding shouldForwardProps to the styled component. return <StyledButton anclick={anclick} anevent={anevent} atc={atc} btnsize={btnsize} btnwidth={btnwidth} disabled={disabled} id={id} onClick={this.onClick} type={type} ref={forwardedRef} shouldForwardProps {...this.props} > {children} ; ------------------------------ You can view, comment on, or merge this pull request online at: #2780 Commit Summary - Add new param shouldForwardProps to allow the passing in of 'invalid' attributes. File Changes - M packages/styled-components/src/models/StyledComponent.js https://github.com/styled-components/styled-components/pull/2780/files#diff-0 (5) Patch Links: - https://github.com/styled-components/styled-components/pull/2780.patch - https://github.com/styled-components/styled-components/pull/2780.diff — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <#2780?email_source=notifications&email_token=AAELFVWKCQIRYG3CDJEKRSDQMX5Z7A5CNFSM4I5DZO4KYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HPNNCGA>, or mute the thread https://github.com/notifications/unsubscribe-auth/AAELFVWI63ENQLXMQF73QH3QMX5Z7ANCNFSM4I5DZO4A .

@quantizor

Copy link
Copy Markdown
Contributor

@mxstbr @kitten thoughts?

@alexandernanberg

Copy link
Copy Markdown
Member

If we were to add something like this, I think emotions way is a better choice.

I'm all for adding this functionality, currently we have to "hack" around this with a custom component passed through the as prop. But I don't think a shouldForwardProps prop is the way to go

@quantizor

Copy link
Copy Markdown
Contributor

I agree with @alexandernanberg. Thanks for your PR but not the overall solution we're aiming for...

@quantizor quantizor closed this Jan 31, 2020
@alexandernanberg

alexandernanberg commented Jan 31, 2020 •

Copy link
Copy Markdown
Member

@probablyup If I'd open a PR with the proposed solution, is that something you'd consider merging? Or is more discussion around this needed?

@quantizor

quantizor commented Jan 31, 2020 via email

Copy link
Copy Markdown
Contributor

@penx

penx commented Feb 7, 2020

Copy link
Copy Markdown

As far as I'm aware, #2392 implemented shouldForwardProp in the same way as emotion.

Can this PR be reopened?

@karlhorky

Copy link
Copy Markdown
Contributor

Looks like @stevesims reopened in #3006 👍

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.

5 participants