Skip to content

Commit

Permalink
Merge 6555591 into c090174
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthkp authored Mar 19, 2024
2 parents c090174 + 6555591 commit 4c4834d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
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
Expand Up @@ -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'
Expand All @@ -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'
Expand Down Expand Up @@ -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={{
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions packages/react/src/UnderlineNav/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 4c4834d

Please sign in to comment.