@@ -8,7 +8,6 @@ import {useResizeObserver, ResizeObserverEntry} from '../hooks/useResizeObserver
8
8
import { useFocusZone } from '../hooks/useFocusZone'
9
9
import { FocusKeys } from '@primer/behaviors'
10
10
11
- type Overflow = 'auto' | 'menu' | 'scroll'
12
11
type ChildWidthArray = Array < { width : number } >
13
12
type ResponsiveProps = {
14
13
items : Array < React . ReactElement >
@@ -40,16 +39,23 @@ const overflowEffect = (
40
39
items . push ( ...childArray )
41
40
} else {
42
41
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
+ }
50
57
}
51
58
}
52
- // TODO: Scroll behaviour to implement (for coarse pointers)
53
59
}
54
60
55
61
callback ( { items, actions} , iconsVisible )
@@ -78,7 +84,6 @@ function calculatePossibleItems(childWidthArray: ChildWidthArray, width: number)
78
84
export type UnderlineNavProps = {
79
85
label : string
80
86
as ?: React . ElementType
81
- overflow ?: Overflow
82
87
align ?: 'right'
83
88
sx ?: SxProp
84
89
variant ?: 'default' | 'small'
@@ -88,16 +93,7 @@ export type UnderlineNavProps = {
88
93
89
94
export const UnderlineNav = forwardRef (
90
95
(
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 ,
101
97
forwardedRef
102
98
) => {
103
99
const backupRef = useRef < HTMLElement > ( null )
@@ -120,7 +116,12 @@ export const UnderlineNav = forwardRef(
120
116
align : 'row' ,
121
117
alignItems : 'center'
122
118
}
123
- const overflowStyles = overflow === 'scroll' ? { overflowX : 'auto' , whiteSpace : 'nowrap' } : { }
119
+
120
+ const overflowStyles = {
121
+ overflowX : 'auto' ,
122
+ whiteSpace : 'nowrap'
123
+ }
124
+
124
125
const ulStyles = {
125
126
display : 'flex' ,
126
127
listStyle : 'none' ,
@@ -170,13 +171,11 @@ export const UnderlineNav = forwardRef(
170
171
// resizeObserver calls this function infinitely without a useCallback
171
172
const resizeObserverCallback = useCallback (
172
173
( 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 )
178
177
} ,
179
- [ callback , childWidthArray , noIconChildWidthArray , children , overflow ]
178
+ [ callback , childWidthArray , noIconChildWidthArray , children ]
180
179
)
181
180
useResizeObserver ( resizeObserverCallback , newRef as RefObject < HTMLElement > )
182
181
return (
0 commit comments