Skip to content

Commit 16a7f3d

Browse files
fix: screenreader focus fix
1 parent c0c6e4a commit 16a7f3d

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

src/components/Dropdown/Dropdown.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
DropdownRef,
2929
} from './Dropdown.types';
3030
import { Menu } from '../Menu';
31+
import { List } from '../List';
3132
import { useMergedState } from '../../hooks/useMergedState';
3233
import { useOnClickOutside } from '../../hooks/useOnClickOutside';
3334
import { usePreviousState } from '../../hooks/usePreviousState';
@@ -461,7 +462,9 @@ export const Dropdown: FC<DropdownProps> = React.memo(
461462
role={role}
462463
{...overlayProps}
463464
>
464-
{overlay}
465+
{React.cloneElement(overlay, {
466+
...(overlay.type === List ? { initialFocus } : {}),
467+
})}
465468
</div>
466469
</FloatingFocusManager>
467470
);

src/components/List/List.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const List = <T extends any>({
1919
disableKeys = false,
2020
items,
2121
footer,
22+
initialFocus = true,
2223
layout = 'vertical',
2324
renderAdditionalItem,
2425
renderItem,
@@ -221,7 +222,6 @@ export const List = <T extends any>({
221222
ref={itemRef}
222223
style={itemStyle}
223224
role="option"
224-
aria-selected={focusIndex === index ? 'true' : 'false'}
225225
tabIndex={focusIndex === index ? 0 : -1}
226226
>
227227
{renderItem(item)}

src/components/List/List.types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,8 @@ export interface ListProps<T> extends OcBaseProps<HTMLDivElement> {
9191
* @default false
9292
*/
9393
applyCyclicNavigation?: boolean;
94+
/**
95+
* Initial focus for the list.
96+
*/
97+
initialFocus?: boolean;
9498
}

0 commit comments

Comments
 (0)