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

[BUG] - The Tabs component often fails to click when using tap to click on the macOS touchpad. #1538

Closed
u3u opened this issue Sep 1, 2023 · 23 comments · Fixed by #2725
Closed
Labels
🐛 Type: Bug Something isn't working

Comments

@u3u
Copy link
Contributor

u3u commented Sep 1, 2023

NextUI Version

2.1.7

Describe the bug

Screen.Recording.2023-09-01.at.21.57.19.mov

Your Example Website or App

No response

Steps to Reproduce the Bug or Issue

https://nextui.org/docs/components/tabs#usage

image

Expected behavior

Every time you tap the Tab, it should work.

Screenshots or Videos

No response

Operating System Version

macOS

Browser

Chrome

@u3u u3u added the 🐛 Type: Bug Something isn't working label Sep 1, 2023
@jrgarciadev
Copy link
Member

@u3u
Copy link
Contributor Author

u3u commented Sep 2, 2023

Hi, it still occurs on my end, only happening when lightly tapping the touchpad (no issue when pressing down firmly). I've tried multiple times and occasionally there is a problem where clicking doesn't switch tabs. I wonder if there is any special handling of click events internally? I suspect it might be an issue with React Aria because it seems similar to #1349.

I think if it only adds onClick event to the Tab button to update the state, this problem is unlikely to occur. There must be other additional processing for clicks or touches that may cause this problem.

If allowed to add additional onClick event to the Tab button, it can be debugged, and should be able to force update the Tab in controlled mode.

Screen.Recording.2023-09-02.at.12.03.14.mov

@u3u
Copy link
Contributor Author

u3u commented Sep 3, 2023

I have confirmed that onSelectionChange does not always trigger when a tab is clicked.
I fixed it by delegating the page click event.

useEventListener('click', (e) => {
  const el = e.target as HTMLElement | undefined;
  const button = el?.closest?.<HTMLButtonElement>('button[data-slot="tab"]');

  if (button) {
    const key = button?.dataset.key as TabKey;

    setSelectedTab(key);
  }
});

@dmythro
Copy link

dmythro commented Sep 3, 2023

I also have this issue sometimes with tap to click on macOS with Accordion.

@vikram-s-narayan
Copy link

Hey @u3u try again using this codesandbox: https://codesandbox.io/p/sandbox/dwvtlf?file=%2FApp.jsx&utm_medium=sandpack

It works fine for me btw: https://github.com/nextui-org/nextui/assets/30373425/6a6a22c2-c66d-4338-b993-000da735b496

I have the same issue with the provided code in codesandbox. Tapping does not effect a change from photos to music to videos.

@caudurodev
Copy link

I had the same issue when running playwright e2e tests - it cannot click the tabs. Adding the event listener as described by u3u fixed it.

@amirstepT
Copy link

amirstepT commented Nov 25, 2023

I'm having this issue with Accordion, Dropdown menu (only the items, not the button), and Tabs. The NextUI website itself has tons of tabs (Preview - Code) scattered throughout, and this issue keeps happening there as well. It's inconsistent though, I'd say it fails to engage the tab (or accordion etc) about 70% of the time with a tap on the mac trackpad. Happens in firefox and chrome.

The fix above by u3u fixed it for me as well (at least for tabs, haven't tested the others). I suspect a problem with usePress.

Edit: I tested this again. It works perfectly on my old Macbook Pro 2013, but is not working on a Mac trackpad associated with my iMac 2016.

@jeffmbreis
Copy link

The @u3u work around works good for single tabs usage, in my case i have two in the same page and the listener is called twice.

+1

@ncullen93
Copy link

I'm also having this issue - a light click on mac fails to register quite often. It makes the tabs borderline unusable.

@aecsar
Copy link

aecsar commented Jan 30, 2024

Is this fixed in the latest version, @jrgarciadev ?

@jeffmbreis
Copy link

@aecsar In the version that is on CodeSandbox that @jrgarciadev created, the problem persists, the problem only occurs using the "Touch click" of a Mackbook.

@dmythro
Copy link

dmythro commented Jan 30, 2024

@aecsar In the version that is on CodeSandbox that @jrgarciadev created, the problem persists, the problem only occurs using the "Touch click" of a Mackbook.

A lot of people just use a MacBook, without any mouse :) Me included. Even at home with a big screen. So you might have an idea how annoying this bug is — and it affects a lot of components (tabs, drop-downs, accordion etc). I wish I had time to dig into this, but in this case I need to get familiar with the whole codebase and this step pushes me back for now. Was hoping core devs have an idea :)

P.S. I had problems with my wrist while using a mouse a long time ago and it was gone when I switched to trackpads permanently.

@aecsar
Copy link

aecsar commented Jan 31, 2024

Really hoping to see a fix in next versions. It's a very bad UX actually.

@Shakahs
Copy link

Shakahs commented Feb 1, 2024

Not just bad UX, this is a blocker from adopting NextUI in our project.

@nextui-org/use-aria-press is handling mouse/touch events and doing event propagation for multiple components including Accordion. I wonder if the bug is here.

@Alex20180512
Copy link

import { Tabs as NextTabs, TabsProps } from "@nextui-org/react";
import { ReactElement } from "react";

export const Tabs: <T = object>(props: TabsProps<T>) => ReactElement = (props) => {
  return (
    <NextTabs
      onClick={(e) => {
        const target = e.target as HTMLElement;
        const selected = target.parentElement!.getAttribute("data-selected");
        const key = target.parentElement!.getAttribute("data-key")! as string;
        if (!selected && key) {
          props.onSelectionChange!(key);
        }
      }}
      {...props}
    />
  );
};

@js-ying
Copy link

js-ying commented Mar 24, 2024

I have the same problem. Pls fix this bug! 🙏

@6peterlu
Copy link

6peterlu commented Apr 1, 2024

Confirming this issue still persists in the latest version in Dropdown and in Buttons.

@6peterlu
Copy link

6peterlu commented Apr 1, 2024

Actually, for me it's mostly been issues with dropdown items, and I was able to get it to work much better by moving my logic to the onClick of each item instead of in onAction.

@Ad-Mora
Copy link

Ad-Mora commented Apr 19, 2024

Also seeing this issue when using the Switch component.

Edit: no longer seeing this issue with the Switch component. Unsure if some unrelated update remedied it, but in any case it doesn't seem to be an issue anymore.

@kevinxmyr
Copy link

Even though the website of NextUI says that the Tabs section is updated as of my writing, it still has bugs. I can't click component when im using responsive design mode in firefox even when i tap lightly and hard. Please fix this issue. im 75% in my project and implemented a lot from NextUI.

@kevinxmyr
Copy link

im having te same issue. go here https://nextui.org/docs/components/tabs and if you are using web browser in pc/mac activate the reponsive mode and turn on the touch. i didnt work too. tabs dont get selected. how can we fix this?

@ridays2001
Copy link

ridays2001 commented May 13, 2024

Hey u3u try again using this codesandbox: https://codesandbox.io/p/sandbox/dwvtlf?file=%2FApp.jsx&utm_medium=sandpack

It works fine for me btw: https://github.com/nextui-org/nextui/assets/30373425/6a6a22c2-c66d-4338-b993-000da735b496

The Code sandbox you provided and even the entire docs website does not work with a tap to click on the MacOS trackpad. It works if I double-tap or press to click. It used to work fine on a Windows laptop trackpad.

Also, the react-aria component works perfectly fine for me - https://react-spectrum.adobe.com/react-aria/Tabs.html

EDIT: I just realized that it works perfectly fine on Safari. This bug is only present on Chromium browsers and Firefox

@ridays2001
Copy link

I found a workaround. It's a very hacky way to fix this, but it works... We need to use controlled tabs and the tab title must be the same as the tab key.

function TabsWrapper() {
	const [selectedTab, setSelectedTab] = useState('First');
	return (
		<Tabs
			aria-label='Tabs'
			selectedKey={selectedTab}
			// @ts-expect-error
			onClick={e => setSelectedTab(e.target.innerText)}
		>
			<Tab key='First' title='First'>
				First Tab Content
			</Tab>
			<Tab key='Second' title='Second'>
				Second Tab Content
			</Tab>
		</Tabs>
	);
}

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