Skip to content

UnderlineNav: Use anchoredPosition to position overflow menu #4414

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

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/quick-icons-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": patch
---

UnderlineNav: Fix position of overflow menu for small screens
11 changes: 7 additions & 4 deletions packages/react/src/UnderlineNav/UnderlineNav.tsx
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ import Box from '../Box'
import type {BetterSystemStyleObject, SxProp} from '../sx'
import sx, {merge} from '../sx'
import {UnderlineNavContext} from './UnderlineNavContext'
import {useAnchoredPosition, useOnEscapePress, useOnOutsideClick, useId} from '../hooks'
import type {ResizeObserverEntry} from '../hooks/useResizeObserver'
import {useResizeObserver} from '../hooks/useResizeObserver'
import {useTheme} from '../ThemeProvider'
@@ -13,9 +14,6 @@ import {moreBtnStyles, getDividerStyle, getNavStyles, ulStyles, menuStyles, menu
import styled from 'styled-components'
import {Button} from '../Button'
import {TriangleDownIcon} from '@primer/octicons-react'
import {useOnEscapePress} from '../hooks/useOnEscapePress'
import {useOnOutsideClick} from '../hooks/useOnOutsideClick'
import {useId} from '../hooks/useId'
import {ActionList} from '../ActionList'
import {defaultSxProp} from '../utils/defaultSxProp'
import CounterLabel from '../CounterLabel'
@@ -295,6 +293,11 @@ export const UnderlineNav = forwardRef(
)
}, navRef as RefObject<HTMLElement>)

const {position: overflowMenuPosition} = useAnchoredPosition(
{anchorElementRef: moreMenuBtnRef, floatingElementRef: containerRef, align: 'end'},
[menuItems.length > 0, isWidgetOpen],
)

return (
<UnderlineNavContext.Provider
value={{
@@ -342,7 +345,7 @@ export const UnderlineNav = forwardRef(
ref={containerRef}
id={disclosureWidgetId}
sx={menuStyles}
style={{display: isWidgetOpen ? 'block' : 'none'}}
style={{display: isWidgetOpen ? 'block' : 'none', ...overflowMenuPosition}}
>
{menuItems.map((menuItem, index) => {
const {
2 changes: 0 additions & 2 deletions packages/react/src/UnderlineNav/styles.ts
Original file line number Diff line number Diff line change
@@ -139,8 +139,6 @@ export const menuItemStyles = {
export const menuStyles = {
position: 'absolute',
zIndex: 1,
top: '90%',
right: '0',
boxShadow: '0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24)',
borderRadius: '12px',
backgroundColor: 'canvas.overlay',