Skip to content

Commit

Permalink
Address Eric's feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
rebeccaalpert committed Nov 5, 2024
1 parent e91991c commit bf5760a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export const ChatbotDemo: React.FunctionComponent = () => {
const [announcement, setAnnouncement] = React.useState<string>();
const scrollToBottomRef = React.useRef<HTMLDivElement>(null);
const toggleRef = React.useRef<HTMLButtonElement>(null);
const chatbotRef = React.useRef<HTMLDivElement>(null);

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

const handleSkipToContent = (e) => {
e.preventDefault();
if (toggleRef.current) {
toggleRef.current.focus();
if (displayMode === ChatbotDisplayMode.default) {
if (toggleRef.current) {
toggleRef.current.focus();
}
} else {
if (chatbotRef.current) {
chatbotRef.current.focus();
}
}
};

Expand All @@ -301,7 +308,7 @@ export const ChatbotDemo: React.FunctionComponent = () => {
id="chatbot-toggle"
ref={toggleRef}
/>
<Chatbot isVisible={chatbotVisible} displayMode={displayMode}>
<Chatbot isVisible={chatbotVisible} displayMode={displayMode} ref={chatbotRef}>
<ChatbotConversationHistoryNav
displayMode={displayMode}
onDrawerToggle={() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ export const EmbeddedChatbotDemo: React.FunctionComponent = () => {

return (
<Page skipToContent={skipToContent} masthead={masthead} sidebar={sidebar} isContentFilled>
<Chatbot displayMode={displayMode}>
<Chatbot displayMode={displayMode} ref={chatbotRef}>
<ChatbotConversationHistoryNav
displayMode={displayMode}
onDrawerToggle={() => {
Expand Down Expand Up @@ -372,7 +372,7 @@ export const EmbeddedChatbotDemo: React.FunctionComponent = () => {
<ChatbotContent>
{/* Update the announcement prop on MessageBox whenever a new message is sent
so that users of assistive devices receive sufficient context */}
<MessageBox announcement={announcement} ref={chatbotRef}>
<MessageBox announcement={announcement}>
<ChatbotWelcomePrompt
title="Hello, Chatbot User"
description="How may I help you today?"
Expand Down
4 changes: 4 additions & 0 deletions packages/module/src/Chatbot/Chatbot.scss
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,7 @@ html.pf-chatbot-allow--docked {
border-radius: 0;
box-shadow: none;
}

.pf-chatbot-container--embedded {
min-height: 100%;
}
16 changes: 14 additions & 2 deletions packages/module/src/Chatbot/Chatbot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export interface ChatbotProps {
isVisible?: boolean;
/** Custom classname for the Chatbot component */
className?: string;
/** Ref applied to chatbot */
innerRef?: React.Ref<HTMLDivElement>;
}

export enum ChatbotDisplayMode {
Expand All @@ -22,11 +24,12 @@ export enum ChatbotDisplayMode {
fullscreen = 'fullscreen'
}

export const Chatbot: React.FunctionComponent<ChatbotProps> = ({
const ChatbotBase: React.FunctionComponent<ChatbotProps> = ({
children,
displayMode = ChatbotDisplayMode.default,
isVisible = true,
className,
innerRef,
...props
}: ChatbotProps) => {
// Configure docked mode
Expand All @@ -52,9 +55,18 @@ export const Chatbot: React.FunctionComponent<ChatbotProps> = ({
animate={isVisible ? 'visible' : 'hidden'}
{...props}
>
{isVisible ? children : undefined}
{/* Ref is intended for use with skip to chatbot links, etc. */}
{isVisible ? (
<div className={`pf-chatbot-container pf-chatbot-container--${displayMode}`} tabIndex={0} ref={innerRef}>
{children}
</div>
) : undefined}
</motion.div>
);
};

const Chatbot = React.forwardRef((props: ChatbotProps, ref: React.Ref<HTMLDivElement>) => (
<ChatbotBase innerRef={ref} {...props} />
));

export default Chatbot;

0 comments on commit bf5760a

Please sign in to comment.