Skip to content

ContextualMenu A11y Narrator Bug Fix #3905

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
Expand Up @@ -219,6 +219,7 @@ const NestedContextualMenu: React.FunctionComponent = () => {
itemKey="4"
onHoverIn={toggleShowSubmenu}
componentRef={stdMenuItemRef}
expanded={showSubmenu}
/>
{showSubmenu && (
<Submenu target={stdMenuItemRef} onDismiss={onDismissSubmenu} onShow={onShowSubmenu} setShowMenu={toggleShowSubmenu}>
Expand Down Expand Up @@ -446,6 +447,7 @@ const ScrollViewContextualMenu: React.FunctionComponent = () => {
itemKey="3"
onHoverIn={toggleShowSubmenu}
componentRef={stdMenuItemRef}
expanded={showSubmenu}
/>
{showSubmenu && (
<Submenu
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix narrator bug",
"packageName": "@fluentui-react-native/contextual-menu",
"email": "gulnazsayed@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix narrator bug",
"packageName": "@fluentui-react-native/tester",
"email": "gulnazsayed@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import type * as React from 'react';

import type { IViewProps } from '@fluentui-react-native/adapters';
import type { IconProps } from '@fluentui-react-native/icon';
import type { IFocusable, IPressableState } from '@fluentui-react-native/interactive-hooks';
import type { IPressableProps } from '@fluentui-react-native/pressable';
import type { IFocusable, IPressableState, PressablePropsExtended } from '@fluentui-react-native/interactive-hooks';
import type { ITextProps } from '@fluentui-react-native/text';
import type { FontTokens, IForegroundColorTokens, IBackgroundColorTokens, IBorderTokens } from '@fluentui-react-native/tokens';
import type { IRenderData } from '@uifabricshared/foundation-composable';
Expand Down Expand Up @@ -48,7 +47,7 @@ export interface ContextualMenuItemTokens extends FontTokens, IForegroundColorTo
iconWeight?: number;
}

export interface ContextualMenuItemProps extends Omit<IPressableProps, 'onPress'> {
export interface ContextualMenuItemProps extends Omit<PressablePropsExtended, 'onPress'> {
/*
** A unique key-identifier for each menu item
*/
Expand Down
28 changes: 25 additions & 3 deletions packages/components/ContextualMenu/src/SubmenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const SubmenuItem = compose<SubmenuItemType>({
const defaultComponentRef = React.useRef(null);
const {
disabled,
expanded,
itemKey,
icon,
text,
Expand Down Expand Up @@ -147,23 +148,44 @@ export const SubmenuItem = compose<SubmenuItemType>({
const onKeyDownProps = useKeyDownProps(showSubmenuOnKeyDown, ' ', 'Enter', 'ArrowLeft', 'ArrowRight');
const onAccTap = onAccessibilityTap ?? onItemPress;

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

// Merge user accessibility actions with defaults
const finalAccessibilityActions = React.useMemo(() => {
const userActions = userProps.accessibilityActions;
if (userActions && userActions.length > 0) {
return [...defaultAccessibilityActions, ...userActions];
}
return defaultAccessibilityActions;
}, [userProps.accessibilityActions, defaultAccessibilityActions]);

const styleProps = useStyling(userProps, (override: string) => state[override] || userProps[override]);
// create the merged slot props
const slotProps = mergeSettings<SubmenuItemSlotProps>(styleProps, {
root: {
ref: cmRef,
...pressablePropsModified,
...onKeyDownProps,
...rest,
accessible: true,
accessibilityLabel: accessibilityLabel,
accessibilityRole: 'menuitem',
accessibilityState: { disabled: state.disabled ?? false, selected: state.selected },
accessibilityState: { disabled: state.disabled ?? false, expanded: expanded ?? false, selected: state.selected },
accessibilityValue: { text: itemKey },
accessibilityActions: finalAccessibilityActions,
disabled,
focusable: !disabled,
onAccessibilityTap: onAccTap,
...rest,
},
content: {
accessible: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ export const submenuItemName = 'SubmenuItem';
export interface SubmenuItemTokens extends ContextualMenuItemTokens {
chevronColor?: string;
}
export type SubmenuItemProps = ContextualMenuItemProps;
export interface SubmenuItemProps extends ContextualMenuItemProps {
/**
* Whether the submenu is currently expanded/visible
*/
expanded?: boolean;
}

export type SubmenuItemState = ContextualMenuItemState;

Expand Down