Skip to content

feat: add auto-scroll to selected menu items in CustomSlashMenu #13048

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jbronssin
Copy link

@jbronssin jbronssin commented Jul 4, 2025

to resolve the issue #13047

It's my first contribution, I hope it's good enough!

When using the slash command (/) in the notes editor, a menu of commands appears. When navigating this menu with the up and down arrow keys, the selection changes, but the menu itself does not scroll. This means that as the list of commands is long, items outside the visible area cannot be seen when selected.

The issue was located in the [CustomSlashMenu.tsx] component. The menu container didn't have vertical scrolling enabled, and there was no logic to scroll the active item into the visible area.

The fix involved:

Adding overflow-y: auto to the menu's styled container in [CustomSlashMenu.tsx].
Modifying the [DropdownMenuItemsContainer] component to accept and forward a ref using React.forwardRef.
Implementing a useEffect hook in [CustomSlashMenu.tsx] that triggers on selection change. This hook uses a ref to the items container to call scrollIntoView({ block: 'nearest' }) on the currently selected menu item.

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

Adds auto-scrolling functionality to slash command menu for better keyboard navigation in the editor.

  • Modified CustomSlashMenu component with overflow-y: auto and implemented scrollIntoView for auto-scrolling selected items into view
  • Refactored DropdownMenuItemsContainer to use forwardRef pattern enabling proper ref handling for scroll behavior
  • Added container height management in StyledInnerContainer to ensure proper overflow handling
  • Enhanced keyboard navigation accessibility by ensuring selected items remain visible during arrow key navigation
  • Potential performance optimization needed for scrollIntoView behavior to avoid janky scrolling

2 files reviewed, 4 comments
Edit PR Review Bot Settings | Greptile

Copy link
Contributor

github-actions bot commented Jul 4, 2025

Welcome!

Hello there, congrats on your first PR! We're excited to have you contributing to this project.
By submitting your Pull Request, you acknowledge that you agree with the terms of our Contributor License Agreement.

Generated by 🚫 dangerJS against 4203650

Copy link
Contributor

github-actions bot commented Jul 4, 2025

🚀 Preview Environment Ready!

Your preview environment is available at: http://bore.pub:51103

This environment will automatically shut down when the PR is closed or after 5 hours.

Copy link
Member

@charlesBochet charlesBochet left a comment

Choose a reason for hiding this comment

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

Hi @jbronssin, glad to see you here! We should catch up IRL

Regarding your PR:

  • we avoid useEffects as much as possible (as this pattern introduce both race conditions and re-renders which is a nightmare do deal with as the codebase grows) ==> we will prefer synchronous ways. Here, when the event key down is pressed, and we move the selection, we can also make the scroll happen
  • we avoid using forwardRef as this make the API more complex. Most of the time we don't need it

==> your implementation is not the right one according to our standards :)

You can take a look at the Filter dropdown for instance, you'll see that the auto-scrolling happens there. And you should see that the FilterDropdown is using ViewBarFilterDropdownContent itself using a SelectableList itself using a SelectableListItem

You'll see that SelectableListItem is doing exactly what I'm telling you not to do :p => useEffect. This is the oldway and we will likely refactor this component later.
For now, let's just use the SelectableList in the CommandSlashMenu and we should be all good!

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.

2 participants