|
2 | 2 | // Licensed under the MIT License. |
3 | 3 |
|
4 | 4 | import { IStyle, FontIcon, mergeStyles, Stack, Text } from '@fluentui/react'; |
5 | | -import React from 'react'; |
| 5 | +import React, { useEffect, useState } from 'react'; |
6 | 6 | import { systemMessageIconStyle } from './styles/SystemMessage.styles'; |
7 | 7 | import { ComponentSlotStyle } from '../types'; |
| 8 | +import LiveMessage from './Announcer/LiveMessage'; |
8 | 9 |
|
9 | 10 | /** |
10 | 11 | * Todo: We need to add more types of system messages that we support. |
@@ -37,13 +38,25 @@ export type SystemMessageProps = { |
37 | 38 | export const SystemMessage = (props: SystemMessageProps): JSX.Element => { |
38 | 39 | const { iconName, content } = props; |
39 | 40 | const Icon: JSX.Element = <FontIcon iconName={iconName} className={mergeStyles(systemMessageIconStyle)} />; |
| 41 | + const [liveMessage, setLiveMessage] = useState(''); |
| 42 | + |
| 43 | + useEffect(() => { |
| 44 | + // Timeout is needed to handle situation when the same user joins and leaves a chat a few times in a row, otherwise Narrator won't repeat the system message text. |
| 45 | + // Because delay value is not provided, setMessage function will be executed asynchronously in the next event cycle |
| 46 | + setTimeout(() => { |
| 47 | + setLiveMessage(content); |
| 48 | + }); |
| 49 | + }, [content]); |
40 | 50 |
|
41 | 51 | return ( |
42 | | - <Stack horizontal className={mergeStyles(props?.containerStyle as IStyle)} tabIndex={0}> |
43 | | - {Icon} |
44 | | - <Text style={{ wordBreak: 'break-word' }} role="status" title={content} variant={'small'}> |
45 | | - {content} |
46 | | - </Text> |
47 | | - </Stack> |
| 52 | + <> |
| 53 | + <LiveMessage message={liveMessage} ariaLive="polite" clearOnUnmount={true} /> |
| 54 | + <Stack horizontal className={mergeStyles(props?.containerStyle as IStyle)} tabIndex={0}> |
| 55 | + {Icon} |
| 56 | + <Text style={{ wordBreak: 'break-word' }} role="status" title={content} variant={'small'}> |
| 57 | + {content} |
| 58 | + </Text> |
| 59 | + </Stack> |
| 60 | + </> |
48 | 61 | ); |
49 | 62 | }; |
0 commit comments