primitives icon indicating copy to clipboard operation
primitives copied to clipboard

fix(select): select click event passthrough underneath

Open xmliszt opened this issue 1 year ago • 14 comments

close #1658

Description

The select component has this behaviour when using mobile browsers, or in Chrome mobile simulator. The tapping of an item to select will close the select content wrapper and then trigger onClick event of the element underneath the select content wrapper.

I have experimented it in the storybook as shown in following screenshot:

1

2

As seen from screenshot, I put a button covering the entire view underneath the select component, in the second GIF recording, we can see that the button underneath is clicked when we try to tap to select an item (reflected by the increasing of the counter value).

Hypothesis

In the original handleSelect event listener when an item is selected, the context.onOpenChange(false) was called before the onClick event was triggered. This is because the handleSelect event listener is listening to the onPointerUp event, which will be fired first before onClick event gets fired. Therefore, this results in our select content wrapper being closed before onClick event is fired, causing the onClick event to pass through to the component underneath.

Solution

My proposed solution in this PR is to make sure that onClick event is captured by the select item before the onOpenChange(false) is called which closes the select content wrapper. This can be done by set up two states, one will get updated when onClick on the select item is captured, the other will be updated when onPointerUp on the select item is captured.

Then we just listen to the two states with a useEffect that will handle the effects caused by the changing two states. Once we get both states to be true, basically means our select item has both onPointerUp and onClick event received, then we can safely call onOpenChange(false) to close the select content wrapper.

Result

The result is the onClick event no longer pass through to the component below, as shown in below GIF image:

3

Unit Test ✅

xmliszt avatar Sep 22 '23 16:09 xmliszt

why hasn't this been merged already

jikdo avatar Jan 15 '24 12:01 jikdo

why hasn't this been merged already

still waiting for two more approval. 🙏🏻🙏🏻

xmliszt avatar Jan 15 '24 13:01 xmliszt

Hey. Not to be a random commenter on an open source project demanding my issue get fixed, but is there any chance this could get reviewed and merged in? There's a number of issues filed for this bug and it seems that the issue is fairly well understood and a fix is right here.

tcaputi avatar Feb 26 '24 20:02 tcaputi

@benoitgrelard can you help get this merged?

shawngustaw avatar Mar 08 '24 03:03 shawngustaw

@benoitgrelard the issue is still relevant, any help with reviewing the fix ? 🙏

gorechavka avatar Mar 13 '24 07:03 gorechavka

any update on reviewers?

crivera avatar Apr 05 '24 16:04 crivera

Please merge!

kuki-quupi avatar Apr 10 '24 13:04 kuki-quupi

Maybe we'll get to celebrate the anniversary of this PR 🥳

Oksamies avatar Apr 12 '24 16:04 Oksamies

Maybe we'll get to celebrate the anniversary of this PR 🥳

5 more months to go 🥲

xmliszt avatar Apr 12 '24 16:04 xmliszt

@andy-hook do you have some bandwidth to help get this merged?

shawngustaw avatar Apr 12 '24 17:04 shawngustaw

Hi, we are facing this exact issue when using the Select component inside a Drawer. Is there an update on this ?

HendrickSamuel avatar May 10 '24 07:05 HendrickSamuel

Hi @andy-hook @benoitgrelard , may I kindly ask for your reviews and approval to run the checks whenever you are free please? Thank you so much! 🙏🏻

xmliszt avatar May 16 '24 12:05 xmliszt

Hi, @andy-hook @benoitgrelard, Could you kindly check this PR? Many people including me are waiting for this merge. Thank you very much 🙇

gizumon avatar Aug 17 '24 09:08 gizumon

Sorry this has taken awhile. Adding to my backlog for some manual testing and then I'll merge ASAP. Locked conversation because "fix my issue" and "+1" comments are not helpful.

chaance avatar Aug 21 '24 22:08 chaance