Skip to content

Attaching of onclick handler causes unexpected highlighting in Mobile Safari #238

Closed

Description

@sophiebits

@yungsters's recent commit 4deb0d6 makes onClick work in Mobile Safari by attaching an empty onclick handler on touchstart. However, this causes subtly different behavior from DOM events without React. Consider the JSX:

<div onClick={...}>
    <img src="a.png" />
    <img src="b.png" />
</div>

When an image is tapped, the onclick handler is attached to the image and so when the browser draws the light gray touch highlight, only the image is highlighted.

Compare with the HTML

<div onclick=...>
    <img src="a.png">
    <img src="b.png">
</div>

where the entire div is highlighted when clicking.

Activity

  1. jordwalke commented on Jul 29, 2013

    @jordwalke
    Contributor

    Does it sound like addressing this at the rendering layer is a reasonable approach? Whenever a React instance has an onClick handler, we can render its markup as <div onclick="function(){}" />.

  2. sophiebits commented on Jul 29, 2013

    @sophiebits
    CollaboratorAuthor

    Yes, I think that makes sense.

  3. yungsters commented on Dec 23, 2013

    @yungsters
    Contributor

    @jordwalke Actually, I think an empty onclick="" would work in this case.

  4. syranide commented on May 27, 2014

    @syranide
    Contributor

    http://www.quirksmode.org/blog/archives/2010/09/click_event_del.html

    Apart from its ugliness, I see one problem with this approach: if my guess is right and
    the Apple engineers have in fact disabled click event delegation because of memory
    considerations, this workaround will create new memory problems. Lots of them if you
    have lots of divs that must become clickable.
    
    But that can’t be helped. Event delegation simply must work for the click event, and if
    we have to brute-force it at the expense of memory that’s just too bad for Safari iPhone.
    

    An alternative is to force cursor: pointer on Mobile Safari, since you can't see the cursor no one should care, it only has to exist for that element with a click-handler and it should keep us away from the issue above? I think? (It does have to play nice with style though, which might not be trivial?)

  5. added a commit that references this issue on Aug 13, 2019
  6. added a commit that references this issue on Jun 25, 2026
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