@@ -8,7 +8,6 @@ import {useResizeObserver, ResizeObserverEntry} from '../hooks/useResizeObserver
88import { useFocusZone } from '../hooks/useFocusZone'
99import { FocusKeys } from '@primer/behaviors'
1010
11- type Overflow = 'auto' | 'menu' | 'scroll'
1211type ChildWidthArray = Array < { width : number } >
1312type ResponsiveProps = {
1413 items : Array < React . ReactElement >
@@ -40,16 +39,23 @@ const overflowEffect = (
4039 items . push ( ...childArray )
4140 } else {
4241 iconsVisible = false
43- // This is only for the overflow behaviour (for fine pointers)
44- // if we can't fit all the items without icons, we keep the icons hidden and show the rest in the menu
45- for ( const [ index , child ] of childArray . entries ( ) ) {
46- if ( index < numberOfItemsWithoutIconPossible ) {
47- items . push ( child )
48- } else {
49- actions . push ( child )
42+ // determine the media query pointer.
43+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
44+ const isCoarsePointer = window . matchMedia && window . matchMedia ( '(pointer:coarse)' ) . matches
45+ // TODO: refactor this to avoid nested if else
46+ if ( isCoarsePointer ) {
47+ // TODO: handle scroll overflow here for media course pointer
48+ } else {
49+ // This is only for the overflow behaviour (for fine pointers)
50+ // if we can't fit all the items without icons, we keep the icons hidden and show the rest in the menu
51+ for ( const [ index , child ] of childArray . entries ( ) ) {
52+ if ( index < numberOfItemsWithoutIconPossible ) {
53+ items . push ( child )
54+ } else {
55+ actions . push ( child )
56+ }
5057 }
5158 }
52- // TODO: Scroll behaviour to implement (for coarse pointers)
5359 }
5460
5561 callback ( { items, actions} , iconsVisible )
@@ -78,7 +84,6 @@ function calculatePossibleItems(childWidthArray: ChildWidthArray, width: number)
7884export type UnderlineNavProps = {
7985 label : string
8086 as ?: React . ElementType
81- overflow ?: Overflow
8287 align ?: 'right'
8388 sx ?: SxProp
8489 variant ?: 'default' | 'small'
@@ -88,16 +93,7 @@ export type UnderlineNavProps = {
8893
8994export const UnderlineNav = forwardRef (
9095 (
91- {
92- as = 'nav' ,
93- overflow = 'auto' ,
94- align,
95- label,
96- sx : sxProp = { } ,
97- afterSelect,
98- variant = 'default' ,
99- children
100- } : UnderlineNavProps ,
96+ { as = 'nav' , align, label, sx : sxProp = { } , afterSelect, variant = 'default' , children} : UnderlineNavProps ,
10197 forwardedRef
10298 ) => {
10399 const backupRef = useRef < HTMLElement > ( null )
@@ -120,7 +116,12 @@ export const UnderlineNav = forwardRef(
120116 align : 'row' ,
121117 alignItems : 'center'
122118 }
123- const overflowStyles = overflow === 'scroll' ? { overflowX : 'auto' , whiteSpace : 'nowrap' } : { }
119+
120+ const overflowStyles = {
121+ overflowX : 'auto' ,
122+ whiteSpace : 'nowrap'
123+ }
124+
124125 const ulStyles = {
125126 display : 'flex' ,
126127 listStyle : 'none' ,
@@ -170,13 +171,11 @@ export const UnderlineNav = forwardRef(
170171 // resizeObserver calls this function infinitely without a useCallback
171172 const resizeObserverCallback = useCallback (
172173 ( resizeObserverEntries : ResizeObserverEntry [ ] ) => {
173- if ( overflow === 'auto' || overflow === 'menu' ) {
174- const childArray = getValidChildren ( children )
175- const navWidth = resizeObserverEntries [ 0 ] . contentRect . width
176- overflowEffect ( navWidth , childArray , childWidthArray , noIconChildWidthArray , callback )
177- }
174+ const childArray = getValidChildren ( children )
175+ const navWidth = resizeObserverEntries [ 0 ] . contentRect . width
176+ overflowEffect ( navWidth , childArray , childWidthArray , noIconChildWidthArray , callback )
178177 } ,
179- [ callback , childWidthArray , noIconChildWidthArray , children , overflow ]
178+ [ callback , childWidthArray , noIconChildWidthArray , children ]
180179 )
181180 useResizeObserver ( resizeObserverCallback , newRef as RefObject < HTMLElement > )
182181 return (
0 commit comments