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] - Autocomplete's keyboard shortcuts behave weirdly #3225

Closed
takuyahara opened this issue Jun 9, 2024 · 12 comments · Fixed by #3311
Closed

[BUG] - Autocomplete's keyboard shortcuts behave weirdly #3225

takuyahara opened this issue Jun 9, 2024 · 12 comments · Fixed by #3311
Assignees

Comments

@takuyahara
Copy link

takuyahara commented Jun 9, 2024

NextUI Version

0.0.0-canary-20240607005641

Describe the bug

Autocomplete's keyboard shortcuts behave weirdly as follows. They don't happen in examples on document.

  1. When hitting tab key next autocomplete's textbox is not focused and popover opens but none of keyboard shortcut (ex. arrow up/down, enter, esc, etc...) works.
  2. When autocomplete is the last focusable component, hitting tab key results popover keeps opened.

But when textbox is clicked, hitting tab key focuses to next autocomplete's textbox. This is an expected behavior.

Your Example Website or App

https://stackblitz.com/~/github.com/takuyahara/nextui-autocomplete-issue

Steps to Reproduce the Bug or Issue

  1. Go to the above-mentioned stackblitz page.
  2. Open page in new tab to see an isolated version.
  3. Hit tab key and arrow up/down keys.

Expected behavior

  1. Hitting tab key focuses to next autocomplete's textbox with popover automatically opened and keyboard shortcut (ex. arrow up/down, enter, esc, etc...) works.
  2. When autocomplete is the last focusable component, hitting tab key closes popover.

Screenshots or Videos

Screen.Recording.2024-06-10.at.0.03.49.mp4

Operating System Version

macOS

Browser

Brave v1.66.118 (Chromium v125.0.6422.147)

Copy link

linear bot commented Jun 9, 2024

@takuyahara
Copy link
Author

Another issues found.

Describe the bug

  1. Clicking autocomplete doesn't focus on textbox on first click so input is not accepted. It has to be clicked twice.
  2. When typing in textbox and delete key is hit, focus is automatically blurred.
  3. When popover is opened and outside of the browser is clicked, popover closes. And when inside of the page is clicked popover reopens without keyboard support.

Expected behavior

  1. Clicking autocomplete focuses on textbox on first click.
  2. Hitting delete key in textbox doesn't blur.
  3. When inside of the page is clicked again, textbox is focused and popover reopens without keyboard support.

Screenshots or Videos

Screen.Recording.2024-06-10.at.0.54.22.mp4

@takuyahara takuyahara changed the title [BUG] - Autocomplete's keyboard behaves weirdly [BUG] - Autocomplete's keyboard shortcuts behave weirdly Jun 9, 2024
@wingkwong
Copy link
Member

This is what I see. Just use tab and arrow down key.

issue3225.webm

@takuyahara
Copy link
Author

It's weird, I see the issue on both Windows and macOS with Chrome, Brave and Safari. I wonder if you are looking the stackblitz link because in your video I see some padding on top of the page but it doesn't exist actually.

@wingkwong
Copy link
Member

@takuyahara i was testing on my local tho.

@takuyahara
Copy link
Author

@wingkwong Could you please check on stackblitz? This is where I see the issue (and on my local as well of course).

https://stackblitz.com/~/github.com/takuyahara/nextui-autocomplete-issue

@takuyahara
Copy link
Author

@wingkwong I hope you have time to see. Let me know if something is lacking.

@wingkwong
Copy link
Member

@takuyahara I could see the error on my next app also but not in storybook n doc. Need to dig a bit.

@takuyahara
Copy link
Author

@wingkwong Just a quick note: downgrading @nextui-org/react to 2.2.10 fixed the issue. Still not sure why it doesn't reproduce in storybook but I see this part causes a problem. If you comment L112 out it solves issue.

const dialogRef = React.useRef(null);
const {dialogProps: ariaDialogProps, titleProps} = useDialog({}, dialogRef);
const dialogProps = getDialogProps({
ref: dialogRef,
...ariaDialogProps,
});

@takuyahara
Copy link
Author

takuyahara commented Jun 18, 2024

Maybe the difference that the issue happens in app but doesn't in storybook is by a difference of bundler. NextUI components are bundled by tsup but storybook bundles with Vite if I understand properly.

It's by React strict mode. See #3225 (comment)

@wingkwong wingkwong self-assigned this Jun 20, 2024
@wingkwong
Copy link
Member

There's lots of diff between 2.2.10 and 2.4.2. We had some major dependencies upgrades in-between. To share more context here, in dialog's focus management, focus is moved into the dialog on mount and restored to the trigger on unmount. In autocomplete, the focus behaviour is a little bit different. We set the focus whenever the popover is open in use-autocomplete.ts.

@takuyahara
Copy link
Author

takuyahara commented Jun 21, 2024

Quick note: I found the issue is caused by React's strict mode. Removing <React.StrictMode> from root component fixes the issue and this is why it doesn't reproduce in Storybook because strict mode is disabled. When enabled the issue reproduces in Storybook as well.

framework: {
name: getAbsolutePath("@storybook/react-vite"),
options: {}
},

-   options: {}
+   options: {
+     strictMode: true,
+   }

But since, as far as I know, the use of strict mode is not restricted in NextUI every component should work on both strict and non-strict mode. It seems like there's something to be destructed on unmount and digging into use-autocomplete.ts (thank you for your suggestion @wingkwong).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants