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

Update menu state to auto wrap popover usages with the menu state context provider #1030

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

andrewkfiedler
Copy link
Contributor

  • This will automatically handle the majority of use cases, as most times in the application we are directly feeding popover props to a popover. Now those components within will automatically get wrapped with the relevant menu state context.
  • For other uses, we provide MenuStateProviderInstance as a convenience for wrapping components with context.
  • Updates some of the function calls to utilize useCallback when possible, to minimize rerenders.
  • Adds some default implementations for the context functions that will show warnings to devs in the console if they happen to be used in a situation where menu state context is missing.

@andrewkfiedler
Copy link
Contributor Author

build now

@cxddfuibot
Copy link
Collaborator

Internal build has been started, your results will be available at build completion.

setOpen(!open)
}
const handleClick = React.useCallback(() => {
setOpen((currentValue) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated this one to a callback and used the ability to access previous value so we could keep the dependency array blank

MuiPopoverProps: {
open,
onClose: handleClose,
anchorEl: anchorRef.current,
action,
ref: popoverRef.ref,
...POPOVER_DEFAULTS({ maxHeight }),
slotProps: {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In most cases we use these popover props, splatting them into the popover, so we'll now automatically get the menu context in those cases.

@@ -137,7 +199,10 @@ export function useMenuState({ maxHeight }: Props = {}) {
ref: anchorRef,
onClick: handleClick,
},
MenuStateProviderInstance,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For other use cases not using popovers, we have this as a convenience for wrapping things with the menu context.

@cxddfuibot
Copy link
Collaborator

Build SUCCESS See the job results in legacy Jenkins UI or in Blue Ocean UI.

@andrewkfiedler andrewkfiedler force-pushed the UpdateMenuStateContext branch from b29dd0a to f5c5bb5 Compare March 19, 2025 03:52
…text provider

 - This will automatically handle the majority of use cases, as most times in the application we are directly feeding popover props to a popover. Now those components within will automatically get wrapped with the relevant menu state context.
 - For other uses, we provide MenuStateProviderInstance as a convenience for wrapping components with context.
 - Updates some of the function calls to utilize useCallback when possible, to minimize rerenders.
 - Adds some default implementations for the context functions that will show warnings to devs in the console if they happen to be used in a situation where menu state context is missing.
 - Adds a convenient method for closing nested menus all at once
 - Removes unused better click away listener
@andrewkfiedler andrewkfiedler force-pushed the UpdateMenuStateContext branch from f5c5bb5 to 92369f1 Compare March 19, 2025 04:32
@@ -28,7 +28,6 @@ class SubscribableNavigationContextClass extends Subscribable<{
) {
this.navigationContext = navigationContext
this._notifySubscribers({ thing: 'update' })
console.log('updateNavigationContext', navigationContext)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removing some chatty console logs that we don't need.

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

Successfully merging this pull request may close these issues.

3 participants