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

Accessible without Input #220

Open
zeroliu opened this issue Feb 28, 2024 · 5 comments
Open

Accessible without Input #220

zeroliu opened this issue Feb 28, 2024 · 5 comments

Comments

@zeroliu
Copy link

zeroliu commented Feb 28, 2024

Hi! I'm building Select/MultiSelect components using cmdk (coming from shadcn/ui). I wonder whether the input is considered a required component in the command tree.

Here's an example without Input. The component cannot be focused any more without input, thus, the list cannot be controlled by keyboard any more.
https://codesandbox.io/p/sandbox/eloquent-ishizaka-2tlr9l?file=/src/App.tsx:9,30

@Only8Bytes
Copy link

+1

Encountering a similar issue. Keyboard navigation with arrow keys does not work when input is not selected, so would make sense that it also wouldn't work when the component doesn't exist

@apolofreitas
Copy link

apolofreitas commented Mar 3, 2024

turns out if you have the #cmdk-root (or any element inside it) focused the navigation will work, so if you dont put a Input component you'll have to manually focus the div.

if youre using @radix-ui/react-popover as shown in documentation you should try adding asChild prop to Popover.Content. Radix behavior is to auto focus the popover content.

i believe it would be useful to have this info in the readme.

@skelawsky
Copy link

turns out if you have the #cmdk-root (or any element inside it) focused the navigation will work, so if you dont put a Input component you'll have to manually focus the div.

if youre using @radix-ui/react-popover as shown in documentation you should try adding asChild prop to Popover.Content. Radix behavior is to auto focus the popover content.

i believe it would be useful to have this info in the readme.

Could you please provide some simplified example? I am having trouble making it work according to your way.

@callumbooth
Copy link

turns out if you have the #cmdk-root (or any element inside it) focused the navigation will work, so if you dont put a Input component you'll have to manually focus the div.
if youre using @radix-ui/react-popover as shown in documentation you should try adding asChild prop to Popover.Content. Radix behavior is to auto focus the popover content.
i believe it would be useful to have this info in the readme.

Could you please provide some simplified example? I am having trouble making it work according to your way.

@skelawsky I added tabIndex={0} to the <Command /> component, that allows the command to be focused, and the keyboard nav to work.

        <Command
          tabIndex={0}
          className="outline-none" //hides focused outline
        >

@joaopedrodcf
Copy link

turns out if you have the #cmdk-root (or any element inside it) focused the navigation will work, so if you dont put a Input component you'll have to manually focus the div.
if youre using @radix-ui/react-popover as shown in documentation you should try adding asChild prop to Popover.Content. Radix behavior is to auto focus the popover content.
i believe it would be useful to have this info in the readme.

Could you please provide some simplified example? I am having trouble making it work according to your way.

@skelawsky I added tabIndex={0} to the <Command /> component, that allows the command to be focused, and the keyboard nav to work.

        <Command
          tabIndex={0}
          className="outline-none" //hides focused outline
        >

Thanks for this solution worked really well 🥇

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

No branches or pull requests

6 participants