Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "expand collapse",
"packageName": "@fluentui-react-native/experimental-menu-button",
"email": "[email protected]",
"dependentChangeType": "patch"
}
38 changes: 37 additions & 1 deletion packages/experimental/MenuButton/src/MenuButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/** @jsxRuntime classic */
/** @jsx withSlots */
import React, { useRef, useState, useCallback } from 'react';
import React, { useRef, useState, useCallback, useMemo } from 'react';
import { Platform } from 'react-native';

import { ButtonV1 as Button } from '@fluentui-react-native/button';
import type { UseSlots } from '@fluentui-react-native/framework';
Expand Down Expand Up @@ -37,6 +38,38 @@ export const MenuButton = compose<MenuButtonType>({
setShowContextualMenu(!showContextualMenu);
}, [showContextualMenu, setShowContextualMenu]);

// Default accessibility actions to help screen readers announce expanded/collapsed state
// Only provide on win32 to follow platform-specific accessibility patterns
const defaultAccessibilityActions = useMemo(() => {
if (Platform.OS === ('win32' as any)) {
return [
{ name: 'Expand', label: 'Expand menu' },
{ name: 'Collapse', label: 'Collapse menu' },
];
}
return [];
}, []);

const onAccessibilityAction = useCallback(
(event) => {
if (Platform.OS === ('win32' as any)) {
switch (event.nativeEvent.actionName) {
case 'Expand':
if (!showContextualMenu) {
setShowContextualMenu(true);
}
break;
case 'Collapse':
if (showContextualMenu) {
setShowContextualMenu(false);
}
break;
}
}
},
[showContextualMenu],
);

const buttonProps = {
disabled,
appearance,
Expand All @@ -45,6 +78,9 @@ export const MenuButton = compose<MenuButtonType>({
componentRef: stdBtnRef,
onClick: toggleShowContextualMenu,
iconOnly: content ? false : true,
accessibilityState: { expanded: showContextualMenu },
accessibilityActions: defaultAccessibilityActions,
onAccessibilityAction,
...rest,
};

Expand Down
Loading