Skip to content

Conversation

@snowystinger
Copy link
Member

@snowystinger snowystinger commented Jan 27, 2021

Closes #1155
Also makes use of shouldCloseOnInteractOutside which reduces the number of times onOpenChange gets called, see https://github.com/adobe/react-spectrum/pull/1510/files#diff-5861ee186d3230691b6ff7f9ee6864ee290647d89e983003e1edfff6fcd6aa5eL225

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

Added new stories in storybook with two menu/picker/etc in them, check those

🧢 Your Project:

@adobe-bot
Copy link

Build successful! 🎉

@adobe-bot
Copy link

Build successful! 🎉

onClose: () => void
}

export const visibleOverlays: OpenOverlay[] = [];
Copy link
Member

Choose a reason for hiding this comment

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

We should make sure that this isn't exported from the package (e.g. index.ts).

Copy link
Member

@devongovett devongovett left a comment

Choose a reason for hiding this comment

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

I was still able to reproduce the double open menu with all spectrum components. Popover with no problem, and the others when clicking quickly. Aria stories seem to work though... Maybe something with the animation?

)
)
.add(
'2 popovers',
Copy link
Member

Choose a reason for hiding this comment

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

I am able to open both popovers at the same time. Is that intended?

Copy link
Member Author

Choose a reason for hiding this comment

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

definitely not intentional and i had it fixed at one point
i'll check out what happened and try to get that to work correctly again

<View width="500px">
<Picker label="Test" autoFocus>
.add(
'2 pickers',
Copy link
Member

Choose a reason for hiding this comment

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

Was also able to open two pickers at the same time when clicking quickly...

// Get props for the menu trigger and menu elements
let ref = React.useRef(null);

let shouldCloseOnInteractOutside = (element) => !ref?.current?.contains(element) ?? false;
Copy link
Member

Choose a reason for hiding this comment

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

Why is this prop needed? Would be nice to avoid making everyone writing an overlay pass it in...

@devongovett devongovett added the waiting Waiting on Issue Author label Mar 18, 2021
});

useEffect(() => {
if (isOpen === true && visibleOverlays.length > 1) {
Copy link
Member Author

Choose a reason for hiding this comment

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

@devongovett yep, I think I had it working for one, then changed for the other and forgot to retest. I can reproduce it and I can fix it for one or the other. I'm having trouble solving for both though. It's this line here
having it as 1 solves it for the hooks which have no delay
having it as 0 solves it for the components which have the OpenTransition with a delay of 0 (which gets queued)

without knowing the overlay this trigger is opening, it's hard to determine if it's in the visibleOverlays or not yet

Some thoughts on it so far:
I could pass in overlayRef, if it's undefined then i know we're dealing with the delayed case, but that changes the API unless I make it optional and then because it's checking undefined it's hard to know if it's omitted or just that it's not mounted yet.

We can't check the id of the last visible overlay, the id isn't on the ref, it's somewhere further down in the tree.

We can't pass the id into useOverlay for storage in the array of visibleOverlays because it's on the dialog or menu context, so we'd need to change an API to get it to the useOverlay hook.

I thought about waiting to remove previous overlays dependent on when the new overlay mounts, but if there's a delay bigger than 0 to show it, then that might get a little funny looking? I think it'd be messy to implement as it'd be a new piece of state i think.

@snowystinger
Copy link
Member Author

replaced by new behaviors in #1970

@snowystinger snowystinger deleted the re-explore-double-open-menus branch June 11, 2021 23:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting Waiting on Issue Author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Overlay not closed when clicking another MenuTrigger

3 participants