-
Notifications
You must be signed in to change notification settings - Fork 578
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
Adds open, onOpenChange, and anchorRef props to DropdownMenu #1372
Conversation
🦋 Changeset detectedLatest commit: 8f67fe8 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
size-limit report 📦
|
Let me know if yall think this merits a test! |
const renderMenuAnchor = useCallback( | ||
<T extends React.HTMLAttributes<HTMLElement>>(props: T) => { | ||
return renderAnchor({ | ||
const renderMenuAnchor = useMemo(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious, what happens if both renderAnchor
and anchorRef
are passed to DropdownMenu
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If they're both passed, the renderAnchor
function is called with anchorRef
as a prop (which would mean putting the same ref in two DOM nodes, which seems wrong but I don't know how it'd break. It's almost certainly not an intended usage, but I'm aiming to mirror what I saw elsewhere.
I spoke with @dgreif about this yesterday, and it sounds like the prop types in AnchoredOverlay
could have been narrowed (specifically in AnchoredOverlayPropsWithAnchor
such that anchorRef did not exist), except it made destructuring props messier.
</Box> | ||
</Box> | ||
<DropdownMenu | ||
renderAnchor={null} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is explicitly setting renderAnchor
to null
required in order to use anchorRef
? If so, I can see that being a confusing API for consumers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. I tried to mirror SelectPanel
, where null
and undefined
have two distinct uses:
- Passing
undefined
means that the component should provide a defaultrenderAnchor
method null
means that the component should not provide a default, and instead pass thenull
through to AnchoredOverlay (in the case where you wanted AnchoredOverlay to just use theanchorRef
for anchoring).
It's a little wonky, but my inclination is to try to clean all of these up in a future PR. I'd like to hear your thoughts though!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes look good 👍
I'm looking forward to your follow up PR to clean up the renderAnchor
+ anchorRef
API across all the overlay components 😄
src/DropdownMenu/DropdownMenu.tsx
Outdated
@@ -33,35 +29,53 @@ export interface DropdownMenuProps extends Partial<Omit<GroupedListProps, keyof | |||
* Props to be spread on the internal `Overlay` component. | |||
*/ | |||
overlayProps?: Partial<OverlayProps> | |||
|
|||
/** | |||
* If defined, will control the open/closed state of the overlay. Must be used in conjuction with `onOpenChange`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we be explicit here about how the open
state is managed if open
is not defined? (i.e. it becomes an uncontrolled component)
Co-authored-by: Cole Bemis <[email protected]>
This extends
DropdownMenu
to allow:open
andonOpenChange
propsanchorRef
prop to control the positioning of the overlay.Closes #1369.
Screenshots
Merge checklist
Take a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.