nextui icon indicating copy to clipboard operation
nextui copied to clipboard

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

Open u3u opened this issue 10 months ago • 15 comments

NextUI Version

2.1.7

Describe the bug

https://github.com/nextui-org/nextui/assets/20062482/ce13c1b3-8e02-4434-9e51-58a7ef512af5

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 avatar Sep 01 '23 14:09 u3u

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

jrgarciadev avatar Sep 01 '23 14:09 jrgarciadev

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.

https://github.com/nextui-org/nextui/assets/20062482/3518c0d3-d294-4727-a428-ab243853e8a0

u3u avatar Sep 02 '23 04:09 u3u

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);
  }
});

u3u avatar Sep 03 '23 08:09 u3u

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

dmythro avatar Sep 03 '23 10:09 dmythro

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.

vikram-s-narayan avatar Sep 07 '23 07:09 vikram-s-narayan

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.

caudurodev avatar Nov 24 '23 10:11 caudurodev

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.

amirstepT avatar Nov 25 '23 23:11 amirstepT

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

jeffmbreis avatar Jan 07 '24 22:01 jeffmbreis

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

ncullen93 avatar Jan 12 '24 13:01 ncullen93

Is this fixed in the latest version, @jrgarciadev ?

aecsar avatar Jan 30 '24 13:01 aecsar

@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.

jeffmbreis avatar Jan 30 '24 13:01 jeffmbreis

@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.

dmythro avatar Jan 30 '24 14:01 dmythro

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

aecsar avatar Jan 31 '24 22:01 aecsar

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.

Shakahs avatar Feb 01 '24 04:02 Shakahs

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}
    />
  );
};

Alex20180512 avatar Feb 11 '24 18:02 Alex20180512

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

js-ying avatar Mar 24 '24 15:03 js-ying

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

6peterlu avatar Apr 01 '24 01:04 6peterlu

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.

6peterlu avatar Apr 01 '24 03:04 6peterlu

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.

Ad-Mora avatar Apr 19 '24 17:04 Ad-Mora

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 <Tabs> 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 avatar Apr 29 '24 23:04 kevinxmyr

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?

kevinxmyr avatar Apr 29 '24 23:04 kevinxmyr

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 avatar May 13 '24 15:05 ridays2001

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>
	);
}

ridays2001 avatar May 13 '24 16:05 ridays2001