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] - Focus remain outside Popover component #2992

Open
xylish7 opened this issue May 13, 2024 · 4 comments
Open

[BUG] - Focus remain outside Popover component #2992

xylish7 opened this issue May 13, 2024 · 4 comments
Assignees
Labels
📦 Scope : Components Related to the components 🐛 Type: Bug Something isn't working

Comments

@xylish7
Copy link

xylish7 commented May 13, 2024

NextUI Version

2.3.6

Describe the bug

When the popover is opened via mouse click or keyboard, the focus remains outside of the popover, instead of moving inside the Popover, as mentioned in the docs.

Your Example Website or App

https://nextui.org/docs/components/popover#with-form

Steps to Reproduce the Bug or Issue

To reproduce the issue check Popover with form example from official docs by:

  1. Click on the Cusomize button.
  2. The popover opens, but if Tab key is pressed, the focus is outside the popover and other elements are being focused.

Expected behavior

The focus should be move inside the Popover. When Tab is pressed, Width input should get focused.

Screenshots or Videos

image

Operating System Version

Windows

Browser

Firefox

Copy link

linear bot commented May 13, 2024

@ShrinidhiUpadhyaya
Copy link
Contributor

You could make use of autoFocus prop. Just add it to the first element inside PopoverContent which is the Input with label width.

<Popover showArrow offset={10} placement="bottom">
   <PopoverTrigger>
     <Button color="primary">Customize</Button>
   </PopoverTrigger>
   <PopoverContent className="w-[240px]">
     {(titleProps) => (
       <div className="px-1 py-2 w-full">
         <p className="text-small font-bold text-foreground" {...titleProps}>
           Dimensions
         </p>
         <div className="mt-2 flex flex-col gap-2 w-full">
           <Input autoFocus defaultValue="100%" label="Width" size="sm" variant="bordered" />
           <Input defaultValue="300px" label="Max. width" size="sm" variant="bordered" />
           <Input defaultValue="24px" label="Height" size="sm" variant="bordered" />
           <Input defaultValue="30px" label="Max. height" size="sm" variant="bordered" />
         </div>
       </div>
     )}
   </PopoverContent>
 </Popover>

@xylish7
Copy link
Author

xylish7 commented May 17, 2024

This may be a workaround, but I think this is still a bug. The focus should move by default into the popover as mentioned in the docs, in the Accessibility section.

Also, this is a specific case, where we have an Input and we can use autoFocus. There may be other elements which do no have the autoFocus prop and focus should be inside the Popover, not on a specific element inside of it. Save issue with Dropdown component.

Both Dropdown and Popover should behave like in the example for the landing page of nextui.org, where the focus work as it should.
image

@wingkwong wingkwong self-assigned this May 18, 2024
@wingkwong
Copy link
Member

I second that. Without explicitly setting autofocus, focus should be moved into the popover on mount and restored to the trigger element on unmount.

@wingkwong wingkwong added 🐛 Type: Bug Something isn't working 📦 Scope : Components Related to the components labels May 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 Scope : Components Related to the components 🐛 Type: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants