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

Command menu refactoring #9257

Conversation

bosiraphael
Copy link
Contributor

@bosiraphael bosiraphael commented Dec 27, 2024

Refactored the CommandMenu component to make it more readable and easier to refactor.
The file was way too big so I introduced a few hooks and eliminated code duplication.

Introduced:

  • useMatchCommands hook to match commands with the search

  • useCommandMenuCommands which returns all command menu commands

  • useMatchingCommandMenuCommands to return the commands matched with the search

  • CommandMenuContainer to simplify the DefaultLayout

  • Unmounted the CommandMenu when it wasn't opened to improve performances

I also introduced a new behavior: Automatically select the first item when opening the command menu:
https://github.com/user-attachments/assets/4b683d49-570e-47c9-8939-99f42ed8691c

@bosiraphael bosiraphael linked an issue Dec 27, 2024 that may be closed by this pull request
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

This PR implements automatic first item selection in the command menu to improve keyboard navigation efficiency.

  • Added setSelectedItemId function in useSelectableList.ts to manage item selection state
  • Introduced selectFirstItem boolean prop in SelectableList.tsx with default false value
  • Modified CommandMenu.tsx to enable first item selection via selectFirstItem={true}
  • Implemented selection reset logic before setting new selections to prevent state conflicts
  • Added proper state management for selected items using Recoil selectors and atoms

3 file(s) reviewed, 3 comment(s)
Edit PR Review Bot Settings | Greptile

@bosiraphael bosiraphael changed the title Automatically select the first item when opening the command menu Command menu refactoring Dec 30, 2024
@bosiraphael bosiraphael merged commit 1091bc6 into main Dec 30, 2024
22 checks passed
@bosiraphael bosiraphael deleted the 9251-the-first-item-of-the-command-menu-should-be-focused-on-open branch December 30, 2024 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The first item of the command menu should be focused on open
2 participants