Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The `PopoverButton` and `DisclosureButton` act as a `CloseButton` when used inside of a panel. We conditionally handled the `ref` when it's inside a panel. We wanted to make sure that the callback is stable and used `useEvent`. This seemed to be ok (even though we break the rules of hooks) because a button can only be in a panel or not be in a panel, but it can't switch during the lifetime of the button. But it can, because the way we know whether we are in a Panel relies on a state value which comes from context. The reason we didn't catch this in the `Disclosure`, is because all the state is stable and known by the time the `Panel` opens. But if you use the `defaultOpen` prop, it is already open and then the state is not ready yet. Long story short, moved the `isWithinPanel` check inside the `useEvent(…)` hook that holds the stable function which means that we don't call this hook unconditionally anymore.
- Loading branch information