Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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": "fix: screenreader narration improvements",
"packageName": "@fluentui/react-message-bar-preview",
"email": "lingfangao@hotmail.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export type MessageBarContextValue = {
layout: 'multiline' | 'singleline' | 'auto';
actionsRef: React_2.MutableRefObject<HTMLDivElement | null>;
bodyRef: React_2.MutableRefObject<HTMLDivElement | null>;
titleId: string;
};

// @public
Expand Down Expand Up @@ -105,10 +106,8 @@ export type MessageBarSlots = {
};

// @public
export type MessageBarState = ComponentState<MessageBarSlots> & Required<Pick<MessageBarProps, 'layout' | 'intent'>> & {
export type MessageBarState = ComponentState<MessageBarSlots> & Required<Pick<MessageBarProps, 'layout' | 'intent'>> & Pick<MessageBarContextValue, 'actionsRef' | 'bodyRef' | 'titleId'> & {
transitionClassName: string;
actionsRef: React_2.MutableRefObject<HTMLDivElement | null>;
bodyRef: React_2.MutableRefObject<HTMLDivElement | null>;
};

// @public
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';
import type { MessageBarContextValue } from '../../contexts/messageBarContext';
import * as React from 'react';

export type MessageBarSlots = {
root: Slot<'div'>;
Expand Down Expand Up @@ -32,8 +31,7 @@ export type MessageBarProps = ComponentProps<MessageBarSlots> &
* State used in rendering MessageBar
*/
export type MessageBarState = ComponentState<MessageBarSlots> &
Required<Pick<MessageBarProps, 'layout' | 'intent'>> & {
Required<Pick<MessageBarProps, 'layout' | 'intent'>> &
Pick<MessageBarContextValue, 'actionsRef' | 'bodyRef' | 'titleId'> & {
transitionClassName: string;
actionsRef: React.MutableRefObject<HTMLDivElement | null>;
bodyRef: React.MutableRefObject<HTMLDivElement | null>;
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { getIntrinsicElementProps, slot, useMergedRefs } from '@fluentui/react-utilities';
import { getIntrinsicElementProps, slot, useId, useMergedRefs } from '@fluentui/react-utilities';
import { useAnnounce_unstable } from '@fluentui/react-shared-contexts';
import type { MessageBarProps, MessageBarState } from './MessageBar.types';
import { getIntentIcon } from './getIntentIcon';
Expand All @@ -25,6 +25,7 @@ export const useMessageBar_unstable = (props: MessageBarProps, ref: React.Ref<HT
const actionsRef = React.useRef<HTMLDivElement | null>(null);
const bodyRef = React.useRef<HTMLDivElement | null>(null);
const { announce } = useAnnounce_unstable();
const titleId = useId();

React.useEffect(() => {
const bodyMessage = bodyRef.current?.textContent;
Expand All @@ -42,6 +43,8 @@ export const useMessageBar_unstable = (props: MessageBarProps, ref: React.Ref<HT
root: slot.always(
getIntrinsicElementProps('div', {
ref: useMergedRefs(ref, reflowRef, nodeRef),
role: 'group',
'aria-labelledby': titleId,
...props,
}),
{ elementType: 'div' },
Expand All @@ -57,5 +60,6 @@ export const useMessageBar_unstable = (props: MessageBarProps, ref: React.Ref<HT
transitionClassName,
actionsRef,
bodyRef,
titleId,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ import * as React from 'react';
import { MessageBarContextValues, MessageBarState } from './MessageBar.types';

export function useMessageBarContextValue_unstable(state: MessageBarState): MessageBarContextValues {
const { layout, actionsRef, bodyRef } = state;
const { layout, actionsRef, bodyRef, titleId } = state;

const messageBarContext = React.useMemo(
() => ({
layout,
actionsRef,
bodyRef,
titleId,
}),
[layout, actionsRef, bodyRef],
[layout, actionsRef, bodyRef, titleId],
);

return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import { getIntrinsicElementProps, slot } from '@fluentui/react-utilities';
import type { MessageBarTitleProps, MessageBarTitleState } from './MessageBarTitle.types';
import { useMessageBarContext } from '../../contexts/messageBarContext';

/**
* Create the state required to render MessageBarTitle.
Expand All @@ -15,13 +16,16 @@ export const useMessageBarTitle_unstable = (
props: MessageBarTitleProps,
ref: React.Ref<HTMLElement>,
): MessageBarTitleState => {
const { titleId } = useMessageBarContext();

return {
components: {
root: 'span',
},
root: slot.always(
getIntrinsicElementProps('span', {
ref,
id: titleId,
...props,
}),
{ elementType: 'span' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ export type MessageBarContextValue = {
layout: 'multiline' | 'singleline' | 'auto';
actionsRef: React.MutableRefObject<HTMLDivElement | null>;
bodyRef: React.MutableRefObject<HTMLDivElement | null>;
titleId: string;
};
const messageBarContext = React.createContext<MessageBarContextValue | undefined>(undefined);

export const messageBarContextDefaultValue: MessageBarContextValue = {
titleId: '',
layout: 'singleline',
actionsRef: React.createRef(),
bodyRef: React.createRef(),
Expand Down