Skip to content

Styled components seems not pass onTouchTap prop in basic tags #527

Closed

Description

@ShinyLeee

Version

1.4.3

Reproduction

http://www.webpackbin.com/4JNcGFDKG

Steps to reproduce

Click 4 anchor tags.

Expected Behavior

All anchor tag show alert message box after touchTap or click.

Actual Behavior

The first anchor tag not show alert.

Description

In this reproduction, seems only basic tags can not receive onTouchTap prop.
I am new to styled-components, so if there is something I lost, please tell me.
Thanks!

Activity

  1. jacobp100 commented on Feb 23, 2017

    @jacobp100
    Contributor

    Looking into it, this is a non-standard event that is monkey patched into tags via react-tap-event-plugin. This is an interesting case, because by looking at the code, it seems like there is an (undocumented) API to add these events.

    We filter out non-standard attributes for html elements. I think it would be wrong to add this to that list, and doing that wouldn't extend to other events injected in this way.

    This is ultimately caused by the same underlying issue that is effecting #403.

    If you need a (hacky) workaround, you can do the following,

    const A = (props) => <a {...props} />
    const StyledLink = styled(A)`
      color: red;
    `
    
    <StyledLink onTouchTap={...}>This should work</StyledLink>
  2. ShinyLeee commented on Feb 23, 2017

    @ShinyLeee
    Author

    Thanks for your reply, I think the workaround is more suitable in this case after find out the reason.

  3. jacobp100 commented on Mar 1, 2017

    @jacobp100
    Contributor

    Moving discussion to #439

  4. plankguy commented on Jun 2, 2018

    @plankguy
    Contributor

    I noticed that new React 16.4.0 pointer events aren't in the "non-standard attribute" regex mentioned above. Are there plans to add these in a future release?

    The above work-around gets the job done, but i'd like to see built-in support.

  5. quantizor commented on Jun 2, 2018

    @quantizor
    Contributor
  6. plankguy commented on Jun 3, 2018

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions