Skip to content

Create callback in ActionMenu to get menu direction #5905

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

Closed
cagesellchen opened this issue Apr 8, 2025 · 3 comments · Fixed by #5910
Closed

Create callback in ActionMenu to get menu direction #5905

cagesellchen opened this issue Apr 8, 2025 · 3 comments · Fixed by #5910
Assignees
Labels
product area: copilot This change would support work happening on the Copilot product react

Comments

@cagesellchen
Copy link

What

Add a callback to the ActionMenu component that returns the direction the dropdown menu will appear (above the anchor, below it, left, right)

Why

This will allow consumers of the component to change the order of the list based on the direction the menu will appear. Today, there's no way to accurately determine this.

Usage Example:

In Copilot Immersive, there's an ActionMenu for retrying a Copilot response. When clicked, the options in the dropdown are the various LLMs the user can retry with. There's an additional option, "Try again", which retries with the existing model. The "Try again" option is the one most selected, so it's important to keep it close to the button.

Below Above
screenshot of menu appearing below button screenshot of menu appearing above button

Today, putting the "Try again" option at the beginning or end of the item list is roughly calculated based on the position of the button on the screen:

useEffect(() => {
  // Calculate whether the menu will drop up or drop down.
  // This is so we can dynamically put the "Try again" option closest to the button.
  // Note: this isn't fully accurate for every screen size, but it's close, and preferable to a fixed item ordering.
  if (componentRef.current) {
    const rect = componentRef.current.getBoundingClientRect()
    setMenuDirection(rect.bottom > window.innerHeight / 1.55 ? 'up' : 'down')
  }
}, [menuDirection])

But this calculation isn't accurate for all screen sizes, which is why we want the ability to get the menu direction directly from the component.

@lesliecdubs lesliecdubs added the product area: copilot This change would support work happening on the Copilot product label Apr 8, 2025
@francinelucca francinelucca modified the milestones: FY22 - Q4, FY23 - Q4 Apr 8, 2025
@TylerJDev TylerJDev self-assigned this Apr 14, 2025
@cagesellchen
Copy link
Author

@TylerJDev what's the status of this work? Is it still planned?

@TylerJDev
Copy link
Member

Hey @cagesellchen! Sorry for the delay on this one, should be resolved in #5910 which I'm actively working on! I just pushed some changes, so hopefully we'll get it merged in soon! 😁

@TylerJDev
Copy link
Member

@cagesellchen, this should be available in v37.24.0, which will release either this week or sometime next week!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
product area: copilot This change would support work happening on the Copilot product react
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants