@@ -13,6 +13,7 @@ import {useOnOutsideClick} from '../../hooks/useOnOutsideClick'
13
13
import type { IconButtonProps } from '../../Button'
14
14
import { IconButton } from '../../Button'
15
15
import Box from '../../Box'
16
+ import { ActionMenu } from '../..'
16
17
17
18
type ChildSize = {
18
19
text : string
@@ -46,13 +47,7 @@ const NavigationList = styled.div`
46
47
${ sx } ;
47
48
`
48
49
49
- const MORE_BTN_HEIGHT = 45
50
50
const GAP = 8
51
- const MoreMenuListItem = styled . li `
52
- display: flex;
53
- align-items: center;
54
- height: ${ MORE_BTN_HEIGHT } px;
55
- `
56
51
57
52
const listStyles = {
58
53
display : 'flex' ,
@@ -67,29 +62,15 @@ const listStyles = {
67
62
position : 'relative' ,
68
63
}
69
64
70
- const menuStyles = {
71
- position : 'absolute' ,
72
- zIndex : 1 ,
73
- top : '90%' ,
74
- right : '0' ,
75
- boxShadow : '0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24)' ,
76
- borderRadius : '12px' ,
77
- backgroundColor : 'canvas.overlay' ,
78
- listStyle : 'none' ,
79
- // Values are from ActionMenu
80
- minWidth : '192px' ,
81
- maxWidth : '640px' ,
82
- }
83
-
84
65
const MORE_BTN_WIDTH = 86
85
- const getNavStyles = ( ) => ( {
66
+ const navStyles = {
86
67
display : 'flex' ,
87
68
paddingX : 3 ,
88
69
justifyContent : 'flex-end' ,
89
70
align : 'row' ,
90
71
alignItems : 'center' ,
91
72
maxHeight : '32px' ,
92
- } )
73
+ }
93
74
94
75
const menuItemStyles = {
95
76
textDecoration : 'none' ,
@@ -192,7 +173,6 @@ export const ActionBar: React.FC<React.PropsWithChildren<ActionBarProps>> = prop
192
173
const moreMenuRef = useRef < HTMLLIElement > ( null )
193
174
const moreMenuBtnRef = useRef < HTMLButtonElement > ( null )
194
175
const containerRef = React . useRef < HTMLUListElement > ( null )
195
- const disclosureWidgetId = React . useId ( )
196
176
197
177
const validChildren = getValidChildren ( children )
198
178
// Responsive props object manages which items are in the list and which items are in the menu.
@@ -231,13 +211,6 @@ export const ActionBar: React.FC<React.PropsWithChildren<ActionBarProps>> = prop
231
211
moreMenuBtnRef . current ?. focus ( )
232
212
} , [ ] )
233
213
234
- const onAnchorClick = useCallback ( ( event : React . MouseEvent < HTMLButtonElement > ) => {
235
- if ( event . defaultPrevented || event . button !== 0 ) {
236
- return
237
- }
238
- setIsWidgetOpen ( isWidgetOpen => ! isWidgetOpen )
239
- } , [ ] )
240
-
241
214
useOnEscapePress (
242
215
( event : KeyboardEvent ) => {
243
216
if ( isWidgetOpen ) {
@@ -253,61 +226,52 @@ export const ActionBar: React.FC<React.PropsWithChildren<ActionBarProps>> = prop
253
226
254
227
return (
255
228
< ActionBarContext . Provider value = { { size, setChildrenWidth} } >
256
- < Box ref = { navRef } sx = { getNavStyles ( ) } >
229
+ < Box ref = { navRef } sx = { navStyles } >
257
230
< NavigationList sx = { listStyles } ref = { listRef } role = "toolbar" >
258
231
{ listItems }
259
232
{ menuItems . length > 0 && (
260
- < MoreMenuListItem ref = { moreMenuRef } >
261
- < IconButton
262
- ref = { moreMenuBtnRef }
263
- sx = { moreBtnStyles }
264
- aria-controls = { disclosureWidgetId }
265
- aria-expanded = { isWidgetOpen }
266
- onClick = { onAnchorClick }
267
- aria-label = { `More ${ ariaLabel } items` }
268
- icon = { KebabHorizontalIcon }
269
- />
270
- < ActionList
271
- ref = { containerRef }
272
- id = { disclosureWidgetId }
273
- sx = { menuStyles }
274
- style = { { display : isWidgetOpen ? 'block' : 'none' } }
275
- >
276
- { menuItems . map ( ( menuItem , index ) => {
277
- if ( menuItem . type === ActionList . Divider ) {
278
- return < ActionList . Divider key = { index } />
279
- } else {
280
- const {
281
- children : menuItemChildren ,
282
- //'aria-current': ariaCurrent,
283
- onClick,
284
- icon : Icon ,
285
- 'aria-label' : ariaLabel ,
286
- } = menuItem . props
287
- return (
288
- < ActionList . LinkItem
289
- key = { menuItemChildren }
290
- sx = { menuItemStyles }
291
- onClick = { (
292
- event : React . MouseEvent < HTMLAnchorElement > | React . KeyboardEvent < HTMLAnchorElement > ,
293
- ) => {
294
- closeOverlay ( )
295
- focusOnMoreMenuBtn ( )
296
- typeof onClick === 'function' && onClick ( event )
297
- } }
298
- >
299
- { Icon ? (
300
- < ActionList . LeadingVisual >
301
- < Icon />
302
- </ ActionList . LeadingVisual >
303
- ) : null }
304
- { ariaLabel }
305
- </ ActionList . LinkItem >
306
- )
307
- }
308
- } ) }
309
- </ ActionList >
310
- </ MoreMenuListItem >
233
+ < ActionMenu >
234
+ < ActionMenu . Anchor >
235
+ < IconButton sx = { moreBtnStyles } aria-label = { `More ${ ariaLabel } items` } icon = { KebabHorizontalIcon } />
236
+ </ ActionMenu . Anchor >
237
+ < ActionMenu . Overlay >
238
+ < ActionList >
239
+ { menuItems . map ( ( menuItem , index ) => {
240
+ if ( menuItem . type === ActionList . Divider ) {
241
+ return < ActionList . Divider key = { index } />
242
+ } else {
243
+ const {
244
+ children : menuItemChildren ,
245
+ //'aria-current': ariaCurrent,
246
+ onClick,
247
+ icon : Icon ,
248
+ 'aria-label' : ariaLabel ,
249
+ } = menuItem . props
250
+ return (
251
+ < ActionList . LinkItem
252
+ key = { menuItemChildren }
253
+ sx = { menuItemStyles }
254
+ onClick = { (
255
+ event : React . MouseEvent < HTMLAnchorElement > | React . KeyboardEvent < HTMLAnchorElement > ,
256
+ ) => {
257
+ closeOverlay ( )
258
+ focusOnMoreMenuBtn ( )
259
+ typeof onClick === 'function' && onClick ( event )
260
+ } }
261
+ >
262
+ { Icon ? (
263
+ < ActionList . LeadingVisual >
264
+ < Icon />
265
+ </ ActionList . LeadingVisual >
266
+ ) : null }
267
+ { ariaLabel }
268
+ </ ActionList . LinkItem >
269
+ )
270
+ }
271
+ } ) }
272
+ </ ActionList >
273
+ </ ActionMenu . Overlay >
274
+ </ ActionMenu >
311
275
) }
312
276
</ NavigationList >
313
277
</ Box >
0 commit comments