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

I have a question about the implementation of 'cmdk'. #344

Open
flex-boram opened this issue Feb 12, 2025 · 0 comments
Open

I have a question about the implementation of 'cmdk'. #344

flex-boram opened this issue Feb 12, 2025 · 0 comments

Comments

@flex-boram
Copy link

flex-boram commented Feb 12, 2025

Hello, I am using 'cmdk' quite well.

I noticed that all keydown events under Command.Root are managed under the onKeyDown event of Command.Root. I'm curious why the scope of the event isn't separately defined in this case.

In my situation, I added a custom component under Command.Root, which is not one of the components provided by 'cmdk'. Even when the custom element is focused, I noticed that focus-roving and item selection events behave the same way, and that's why I have this question.

onKeyDown={(e) => {
	etc.onKeyDown?.(e)

	// But we may need to validate all custom attributes with the 'cmdk' prefix.
	if (e.target instanceof HTMLElement && e.target.hasAttribte('cmdk-...')) {
		// block focus-roving and select
	}

	if (!e.defaultPrevented) {
		...
	}
}
import * as Popover from '@radix-ui/react-popover'

return (
  <Popover.Root>
    <Popover.Trigger>Toggle popover</Popover.Trigger>

    <Popover.Content>
      <Command>
        <Command.Input />
        <Command.List>
          <Command.Item>Apple</Command.Item>
        </Command.List>
        {/** I can reach the button via Tab, but I want to block events like Keyboard Up/Down, Enter, and other events that propagate. */}
        <CustomElement>
          <Button>Footer button</Button>
        <CustomElement/>
      </Command>
    </Popover.Content>
  </Popover.Root>
)
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

1 participant