@@ -5,16 +5,19 @@ import React from 'react';
5
5
import JumpButton from './JumpButton' ;
6
6
7
7
export interface MessageBoxProps extends React . HTMLProps < HTMLDivElement > {
8
+ /** Content that can be announced, such as a new message, for screen readers */
9
+ announcement ?: string ;
10
+ /** Custom aria-label for scrollable portion of message box */
11
+ ariaLabel ?: string ;
8
12
/** Content to be displayed in the message box */
9
13
children : React . ReactNode ;
10
14
/** Custom classname for the MessageBox component */
11
15
className ?: string ;
12
- /** Content that can be announced, such as a new message, for screen readers */
13
- announcement ?: string ;
14
16
}
15
17
16
18
const MessageBox : React . FunctionComponent < MessageBoxProps > = ( {
17
19
announcement,
20
+ ariaLabel = 'Scrollable message log' ,
18
21
children,
19
22
className
20
23
} : MessageBoxProps ) => {
@@ -28,7 +31,6 @@ const MessageBox: React.FunctionComponent<MessageBoxProps> = ({
28
31
const element = messageBoxRef . current ;
29
32
if ( element ) {
30
33
const { scrollTop, scrollHeight, clientHeight } = element ;
31
-
32
34
setAtTop ( scrollTop === 0 ) ;
33
35
setAtBottom ( Math . round ( scrollTop ) + Math . round ( clientHeight ) >= Math . round ( scrollHeight ) - 1 ) ; // rounding means it could be within a pixel of the bottom
34
36
}
@@ -76,7 +78,13 @@ const MessageBox: React.FunctionComponent<MessageBoxProps> = ({
76
78
return (
77
79
< >
78
80
< JumpButton position = "top" isHidden = { isOverflowing && atTop } onClick = { scrollToTop } />
79
- < div className = { `pf-chatbot__messagebox ${ className ?? '' } ` } ref = { messageBoxRef } >
81
+ < div
82
+ role = "region"
83
+ tabIndex = { 0 }
84
+ aria-label = { ariaLabel }
85
+ className = { `pf-chatbot__messagebox ${ className ?? '' } ` }
86
+ ref = { messageBoxRef }
87
+ >
80
88
{ children }
81
89
< div className = "pf-chatbot__messagebox-announcement" aria-live = "polite" >
82
90
{ announcement }
0 commit comments