Skip to content

Commit f92cebd

Browse files
committed
Address Eric's feedback
1 parent e91991c commit f92cebd

File tree

4 files changed

+44
-7
lines changed

4 files changed

+44
-7
lines changed

packages/module/patternfly-docs/content/extensions/virtual-assistant/examples/demos/Chatbot.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ export const ChatbotDemo: React.FunctionComponent = () => {
170170
const [announcement, setAnnouncement] = React.useState<string>();
171171
const scrollToBottomRef = React.useRef<HTMLDivElement>(null);
172172
const toggleRef = React.useRef<HTMLButtonElement>(null);
173+
const chatbotRef = React.useRef<HTMLDivElement>(null);
173174

174175
// Autu-scrolls to the latest message
175176
React.useEffect(() => {
@@ -284,8 +285,14 @@ export const ChatbotDemo: React.FunctionComponent = () => {
284285

285286
const handleSkipToContent = (e) => {
286287
e.preventDefault();
287-
if (toggleRef.current) {
288-
toggleRef.current.focus();
288+
if (displayMode === ChatbotDisplayMode.default) {
289+
if (toggleRef.current) {
290+
toggleRef.current.focus();
291+
}
292+
} else {
293+
if (chatbotRef.current) {
294+
chatbotRef.current.focus();
295+
}
289296
}
290297
};
291298

@@ -301,7 +308,7 @@ export const ChatbotDemo: React.FunctionComponent = () => {
301308
id="chatbot-toggle"
302309
ref={toggleRef}
303310
/>
304-
<Chatbot isVisible={chatbotVisible} displayMode={displayMode}>
311+
<Chatbot isVisible={chatbotVisible} displayMode={displayMode} ref={chatbotRef}>
305312
<ChatbotConversationHistoryNav
306313
displayMode={displayMode}
307314
onDrawerToggle={() => {

packages/module/patternfly-docs/content/extensions/virtual-assistant/examples/demos/EmbeddedChatbot.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ export const EmbeddedChatbotDemo: React.FunctionComponent = () => {
319319

320320
return (
321321
<Page skipToContent={skipToContent} masthead={masthead} sidebar={sidebar} isContentFilled>
322-
<Chatbot displayMode={displayMode}>
322+
<Chatbot displayMode={displayMode} ref={chatbotRef}>
323323
<ChatbotConversationHistoryNav
324324
displayMode={displayMode}
325325
onDrawerToggle={() => {
@@ -372,7 +372,7 @@ export const EmbeddedChatbotDemo: React.FunctionComponent = () => {
372372
<ChatbotContent>
373373
{/* Update the announcement prop on MessageBox whenever a new message is sent
374374
so that users of assistive devices receive sufficient context */}
375-
<MessageBox announcement={announcement} ref={chatbotRef}>
375+
<MessageBox announcement={announcement}>
376376
<ChatbotWelcomePrompt
377377
title="Hello, Chatbot User"
378378
description="How may I help you today?"

packages/module/src/Chatbot/Chatbot.scss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,14 @@ html.pf-chatbot-allow--docked {
6464
border-radius: 0;
6565
box-shadow: none;
6666
}
67+
68+
.pf-chatbot-container--embedded {
69+
min-height: 100%;
70+
}
71+
72+
.pf-chatbot-container {
73+
// Hide chatbot
74+
&--hidden {
75+
pointer-events: none;
76+
}
77+
}

packages/module/src/Chatbot/Chatbot.tsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export interface ChatbotProps {
1313
isVisible?: boolean;
1414
/** Custom classname for the Chatbot component */
1515
className?: string;
16+
/** Ref applied to chatbot */
17+
innerRef?: React.Ref<HTMLDivElement>;
1618
}
1719

1820
export enum ChatbotDisplayMode {
@@ -22,11 +24,12 @@ export enum ChatbotDisplayMode {
2224
fullscreen = 'fullscreen'
2325
}
2426

25-
export const Chatbot: React.FunctionComponent<ChatbotProps> = ({
27+
const ChatbotBase: React.FunctionComponent<ChatbotProps> = ({
2628
children,
2729
displayMode = ChatbotDisplayMode.default,
2830
isVisible = true,
2931
className,
32+
innerRef,
3033
...props
3134
}: ChatbotProps) => {
3235
// Configure docked mode
@@ -52,9 +55,25 @@ export const Chatbot: React.FunctionComponent<ChatbotProps> = ({
5255
animate={isVisible ? 'visible' : 'hidden'}
5356
{...props}
5457
>
55-
{isVisible ? children : undefined}
58+
{/* Ref is intended for use with skip to chatbot links, etc. */}
59+
{/* Motion.div does not accept refs */}
60+
{isVisible ? (
61+
<div
62+
role="region"
63+
aria-label={props['aria-label'] ?? 'Chatbot'}
64+
className={`pf-chatbot-container pf-chatbot-container--${displayMode} ${!isVisible ? 'pf-chatbot-container--hidden' : ''}`}
65+
tabIndex={0}
66+
ref={innerRef}
67+
>
68+
{children}
69+
</div>
70+
) : undefined}
5671
</motion.div>
5772
);
5873
};
5974

75+
const Chatbot = React.forwardRef((props: ChatbotProps, ref: React.Ref<HTMLDivElement>) => (
76+
<ChatbotBase innerRef={ref} {...props} />
77+
));
78+
6079
export default Chatbot;

0 commit comments

Comments
 (0)