-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Menu] Fix custom anchor positioning (#609)
- Loading branch information
1 parent
ac6b56c
commit 1ab27b0
Showing
5 changed files
with
184 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use client'; | ||
|
||
import * as React from 'react'; | ||
import * as Menu from '@base_ui/react/Menu'; | ||
|
||
export default function Page() { | ||
const [anchorEl, setAnchor] = React.useState<HTMLDivElement | null>(null); | ||
const handleRef = React.useCallback((element: HTMLDivElement | null) => { | ||
setAnchor(element); | ||
}, []); | ||
|
||
return ( | ||
<div> | ||
<h1>Element passed to anchor</h1> | ||
<Menu.Root animated={false}> | ||
<Menu.Trigger>Trigger</Menu.Trigger> | ||
<Menu.Positioner side="bottom" alignment="start" arrowPadding={0} anchor={anchorEl}> | ||
<Menu.Popup> | ||
<Menu.Item style={{ background: 'lightgray', padding: '5px' }}>One</Menu.Item> | ||
<Menu.Item style={{ background: 'lightgray', padding: '5px' }}>Two</Menu.Item> | ||
</Menu.Popup> | ||
</Menu.Positioner> | ||
</Menu.Root> | ||
<div | ||
data-testid="anchor" | ||
style={{ margin: '100px', background: 'yellowgreen', height: '50px', width: '200px' }} | ||
ref={handleRef} | ||
> | ||
Anchor | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use client'; | ||
|
||
import * as React from 'react'; | ||
import * as Menu from '@base_ui/react/Menu'; | ||
|
||
export default function Page() { | ||
const anchor = React.useRef<HTMLDivElement>(null); | ||
|
||
return ( | ||
<div> | ||
<h1>Ref passed to anchor</h1> | ||
<Menu.Root animated={false}> | ||
<Menu.Trigger>Trigger</Menu.Trigger> | ||
<Menu.Positioner side="bottom" alignment="start" arrowPadding={0} anchor={anchor}> | ||
<Menu.Popup> | ||
<Menu.Item style={{ background: 'lightgray', padding: '5px' }}>One</Menu.Item> | ||
<Menu.Item style={{ background: 'lightgray', padding: '5px' }}>Two</Menu.Item> | ||
</Menu.Popup> | ||
</Menu.Positioner> | ||
</Menu.Root> | ||
<div | ||
data-testid="anchor" | ||
style={{ margin: '100px', background: 'yellowgreen', height: '50px', width: '200px' }} | ||
ref={anchor} | ||
> | ||
Anchor | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters