Skip to content
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

onPress not executed the first time when pressing a Tabs.Tab #2553

Open
wongk opened this issue Apr 17, 2024 · 1 comment
Open

onPress not executed the first time when pressing a Tabs.Tab #2553

wongk opened this issue Apr 17, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@wongk
Copy link

wongk commented Apr 17, 2024

Current Behavior

When I pass an onPress handler for a Tabs.Tab, on native it works correctly, but on web I have to press the tab twice before my handler is executed. This applies to each tab in the tabs list. Starting with the second press, the handler is subsequently executed properly.

Expected Behavior

No response

Tamagui Version

1.94.4

Platform (Web, iOS, Android)

Web

Reproduction

<Tabs.Tab
  onPress={() => {
    alert("Pressed")
  }}
>
  // ...
</Tabs.Tab>


### System Info

_No response_
@ehxxn ehxxn added the bug Something isn't working label Apr 25, 2024
@hollyos
Copy link

hollyos commented May 15, 2024

Diagnosis

Looks like the onPress event handler is getting interference from the web-specific behaviors. Specifically, the onFocus. My thinking is that if the first click sets the focus but does not immediately trigger the tab selection change. Then the second click, finding the tab already focused, successfully triggers the selection change.

Potential Resolution

Could try to adjust the event handling logic to ensure the tab change is triggered on the initial click regardless of the focus state.

Tabs.tsx#L247

  if (!disabled && !isSelected && webChecks) {
    context.onChange(value);

    if (!isSelected) {
      event.preventDefault();
    }
  } else {
    event.preventDefault();
  }

Notes

  • I'm just getting started with Tamagui. I'll give this a try and update soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants