Skip to content

Commit 046a0e6

Browse files
committed
fix: Focus the 'listbox', not the 'dialog'
1 parent 37f2879 commit 046a0e6

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/ActionList/List.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ function useListVariant(variant: ListProps['variant'] = 'inset'): {
132132
/**
133133
* Lists `Item`s, either grouped or ungrouped, with a `Divider` between each `Group`.
134134
*/
135-
export function List(props: ListProps): JSX.Element {
135+
export const List = React.forwardRef<HTMLDivElement, ListProps>((props, ref): JSX.Element => {
136136
// Get `sx` prop values for `List` children matching the given `List` style variation.
137137
const {firstGroupStyle, lastGroupStyle, headerStyle, itemStyle} = useListVariant(props.variant)
138138

@@ -216,7 +216,7 @@ export function List(props: ListProps): JSX.Element {
216216
}
217217

218218
return (
219-
<StyledList {...props}>
219+
<StyledList {...props} ref={ref}>
220220
{groups.map(({header, ...groupProps}, index) => {
221221
const hasFilledHeader = header?.variant === 'filled'
222222
const shouldShowDivider = index > 0 && !hasFilledHeader
@@ -242,4 +242,4 @@ export function List(props: ListProps): JSX.Element {
242242
})}
243243
</StyledList>
244244
)
245-
}
245+
})

src/DropdownMenu/DropdownMenu.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, {useCallback, useMemo, useState} from 'react'
1+
import React, {useCallback, useMemo, useState, useRef} from 'react'
22
import {List, GroupedListProps, ListPropsBase, ItemInput} from '../ActionList/List'
33
import {DropdownButton, DropdownButtonProps} from './DropdownButton'
44
import {ItemProps} from '../ActionList/Item'
@@ -84,15 +84,18 @@ export function DropdownMenu({
8484
})
8585
}, [items, onChange, onClose, selectedItem])
8686

87+
const listRef = useRef<HTMLDivElement>(null)
88+
8789
return (
8890
<AnchoredOverlay
8991
renderAnchor={renderMenuAnchor}
9092
open={open}
9193
onOpen={onOpen}
9294
onClose={onClose}
9395
overlayProps={overlayProps}
96+
focusTrapSettings={{initialFocusRef: listRef}}
9497
>
95-
<List {...listProps} role="listbox" items={itemsToRender} />
98+
<List {...listProps} ref={listRef} role="listbox" items={itemsToRender} />
9699
</AnchoredOverlay>
97100
)
98101
}

0 commit comments

Comments
 (0)