UI

Structure

Container

The PatternFly ChatBot is a separate window that overlays or is embedded within other UI content. This container can be shown and hidden via the ChatBot toggle.

The <Chatbot> component is the container that encompasses the ChatBot experience. It adapts to various display modes (overlay/default, docked, fullscreen, and embedded) and supports both light and dark themes.

The "embedded" display mode is meant to be used within a PatternFly page or other container within your product.

Container screenshot

Content and message box

The <ChatbotContent> component is the container that is placed within the <Chatbot>, between the <ChatbotHeader> and <ChatbotFooter>.

<ChatbotContent> usually contains a <ChatbotMessageBox> for displaying messages.

Your code structure should look like this:

<Chatbot>
  <ChatbotHeader ... />
  <ChatbotContent>
    <ChatbotMessageBox>
    ...
    <ChatbotMessageBox>
  </ChatbotContent>
  <ChatbotFooter ... />
</Chatbot>

Note: When messages update, it is important to announce new messages to users of assistive technology. To do this, make sure to set the announcement prop on <MessageBox> whenever you display a new message in <MessageBox>. You can view this in action in our basic ChatBot and embedded ChatBot demos.

Welcome message

To introduce users to the ChatBot experience, display a welcome message before they input their first message. This brief message should follow our conversation design guidelines to welcome users to the ChatBot experience and encourage them to interact.

This message can be dismissed once a user sends their first message. To change the arrangement of the message within the message box, specify the position in the <MessageBox> component.

Welcome message screenshot

Welcome prompt

To provide users with a more specific direction, you can also include optional welcome prompts.

Hello, Chatbot User
How may I help you today?

Topic 1
Helpful prompt for Topic 1
Topic 2
Helpful prompt for Topic 2

Skip to content

To provide page context, we recommend using a "Skip to chatbot" button. This allows you to skip past other content on the page, directly to the ChatBot content, using a PatternFly skip to content component. To display this button, you must tab into the main window.

When using default or docked modes, we recommend putting focus on the toggle if the ChatBot is closed, and the ChatBot when it is open. For fullscreen and embedded, we recommend putting the focus on the first focusable item in the ChatBot, such as a menu toggle. This can be seen in our more fully-featured demos for the default, embedded, and fullscreen ChatBot and the embedded ChatBot.

Skip to content screenshot

Toggle

Basic toggle

To allow users to open and close the ChatBot window as needed, add a toggle.

Basic toggle screenshot

Custom toggle icon

A custom icon can be passed to the toggle. To ensure the icon is visible in both light and dark themes, use an SVG image and set fill="currentColor".

Custom toggle icon screenshot

Custom toggle shape

A custom shape can be set for the toggle. To override the default circle shape, set isRound to false. This will set the toggle to a square shape, but you can pass in additional classes to further customize the shape.

Custom toggle shape screenshot

Header sections

The ChatBot header is persistent, and contains the title for the ChatBot window, as well as any related controls and actions.

The <ChatbotHeader> has 2 sections:

  • <ChatbotHeaderMain> contains the title and an optional menu toggle:
    • <ChatbotHeaderTitle> handles the layout and display of a title or image at different responsive sizes.
    • <ChatbotHeaderMenu> (optional) is placed on the left side of the header and used to toggle a chat history menu.
  • <ChatbotHeaderActions> contains any additional controls:
    • The <ChatbotHeaderSelectorDropdown> component is a standard PatternFly dropdown that matches the ChatBot styles.
    • The <ChatbotHeaderOptionsDropdown> component is a dropdown with a menu toggle that is intended to be used to update ChatBot settings (like the display mode).

Your <ChatbotHeader> code structure should look like this:

<ChatbotHeader>
  <ChatbotHeaderMain>
    <ChatbotHeaderMenu ... />
    <ChatbotHeaderTitle ... />
  </ChatbotHeaderMain>
  <ChatbotHeaderActions>
    <ChatbotHeaderSelectorDropdown ... />
    <ChatbotHeaderOptionsDropdown ... />
  </ChatbotHeaderActions>
</ChatbotHeader>

Header title

By default, <HeaderTitle> renders any children that are passed in. Optionally, you can pass in a displayMode, showOnEmbedded, showOnDocked, showOnFullScreen, and/or showOnDefault to render content conditionally.

Display mode  
Default

Header options

There are a variety of options and customizations you can make to the header, to adjust how information is displayed, or to add additional controls.

In this example, select the respective checkbox to toggle these features:

  • Menu: Users can select the menu toggle to open a menu of additional options or actions.
  • Left-aligned logo
  • Centered logo
  • Selector dropdown: Users can choose from preselected options in a dropdown menu. For example, they can toggle between AI models.
  • Options dropdown: Users can select ChatBot options from a menu. For example, they can switch between ChatBot display modes.
Variant  
PatternFly
PatternFly

ChatBot Extension


Footnote with popover

A footnote can be placed in the ChatBot footer to communicate any legal disclaimers or information about the ChatBot. Footnotes can be static text or a button that opens a popover.

Message bar with speech recognition and file attachment

In Safari and Chrome, you will see a microphone button in the message bar if hasMicrophoneButton is passed to <MessageBar>. The button will only appear if 'SpeechRecognition' or 'webkitSpeechRecognition' are available in window. This does not currently work in Firefox.

By default the message bar supports file uploads via an attach button. Setting hasAttachButton to false will disable that feature.

Send a message...

Message bar with speech recognition in a different language

Speech recognition defaults to en-US. You can update the locale as needed. Locale codes are a combination of the ISO 639-1 language code and the ISO 3166-1 country code, separated by a hyphen.

In this example, the locale is set to to ja-JP. You can try it out by saying "hajimemashite" (初めまして).

Send a message...

Message bar with attach menu appended to attach button

You can change the behavior of the attach button to open a menu, rather than the default file viewer for your operating system. This menu can display different actions related to attachments.

Attachments can also be added to the ChatBot via drag and drop.

Send a message...

A simple footer with a message bar and footnote would have this code structure:

<ChatbotFooter>
  <MessageBar ... />
  <ChatbotFootnote .../>
</ChatbotFooter>

Message bar with stop button

If you are using streaming, you can add a stop button to the message bar that allows users to stop a response from a ChatBot.

To enable the stop button, set hasStopButton to true and pass in a handleStopButton callback function. You can use this callback to trigger an AbortController configured as part of your API call.

Send a message...

Side nav in a drawer

The ChatBot conversation history is contained in an interactive drawer, where users can interact with previous conversations or start a new conversation.

The <ChatbotConversationHistoryNav> component is a wrapper placed within <Chatbot>, which contains all other ChatBot components in drawerContent. There is a focus trap so users can only tab within the drawer while it is open.

The code structure will look like this:

<Chatbot>
  <ChatbotConversationHistoryNav
    ...
    drawerContent={
        <>
            <ChatbotContent>
                <ChatbotMessageBox>
                ...
                <ChatbotMessageBox>
            </ChatbotContent>
            <ChatbotFooter ... />
        </>
    }>
  </ChatbotConversationHistoryNav>
</Chatbot>

The conversation history drawer looks different depending on the displayMode of the parent <Chatbot>. (As shown in the main ChatBot demo.):

  • Default and docked display modes display the conversation history on top of the rest of the ChatBot content, with a PatternFly backdrop between the drawer panel and drawer content.
  • Fullscreen and embedded display modes display the conversation history in line with the drawer content.

Drawer with search and "new chat" button

In the conversation history drawer, users can search previous ChatBot conversations via an input field. To customize the placeholder text, use searchInputPlaceholder. Provide an aria label via searchInputAriaLabel.

They can also start new conversations via a "New chat" button. To customize the button label, use newChatButtonText.

Both the search input field and "New chat" buttons are optional. The reverseButtonOrder prop allows you to invert the positions of the Close and "New chat" buttons within the drawer when set to true.

Drawer content

Drawer with conversation actions

Actions can be added to conversations with menuItems. Optionally, you can also add a className to the menu via menuClassName, change the default aria-label and tooltip content via label, or add an onSelect callback for when a user selects an item.

Drawer content

Based on the PatternFly modal, this modal adapts to the ChatBot display mode and accepts components typically used in a modal. It is primarily used and tested in the context of the attachment modals, but you can customize this modal to adapt it to other use cases as needed. The modal will overlay the ChatBot in default and docked modes, and will behave more like a traditional PatternFly modal in fullscreen and embedded modes.

Modal screenshot

Props

Chatbot

*required
NameTypeDefaultDescription
childrenrequiredReact.ReactNodeContent to be displayed in the chatbot
ariaLabelstringCustom aria label applied to focusable container
classNamestringCustom classname for the Chatbot component
displayModeChatbotDisplayModeDisplay Mode for the Chatbot
innerRefReact.Ref<HTMLDivElement>Ref applied to chatbot
isVisiblebooleanVisibility flag for the chatbot

ChatbotContent

*required
NameTypeDefaultDescription
childrenrequiredReact.ReactNodeContent to be displayed in the chatbot
classNamestringCustom classname for the ChatbotContent component

MessageBox

*required
NameTypeDefaultDescription
childrenrequiredReact.ReactNodeContent to be displayed in the message box
announcementstringContent that can be announced, such as a new message, for screen readers
ariaLabelstringCustom aria-label for scrollable portion of message box
classNamestringCustom classname for the MessageBox component
innerRefReact.Ref<HTMLDivElement>Ref applied to message box
position'top' | 'bottom'Modifier that controls how content in MessageBox is positioned within the container

ChatbotWelcomePrompt

*required
NameTypeDefaultDescription
descriptionrequiredstringWelcome message
titlerequiredstringTitle for the welcome message
classNamestringCustom classname for the WelcomePrompt component
promptsWelcomePrompt[]Custom basic prompts to help users coming for the first time to chatbot
testIdstringCustom test id for the WelcomePrompt component

WelcomePrompt

*required
NameTypeDefaultDescription
titlerequiredstringTitle for the welcome prompt
messagestringMessage for the welcome prompt
onClick() => voidCallback handler for the onClick event for welcome prompt

ChatbotToggle

*required
NameTypeDefaultDescription
tooltipLabelrequiredReact.ReactNodeContents of the tooltip applied to the toggle button
classNamestringClass name applied to toggle
closedToggleIcon() => JSX.ElementAn image displayed in the chatbot toggle when it is closed
innerRefReact.Ref<HTMLButtonElement>Ref applied to toggle
isChatbotVisiblebooleanFlag indicating visibility of the chatbot appended to the toggle
isRoundbooleanWhether toggle is a circle
onToggleChatbot() => voidCallback fired when toggle button is clicked
openIconTestIdstringTest id applied to default open icon
toggleButtonLabelstringAccessible label for the toggle button
tooltipPropsOmit<TooltipProps, 'content'>Props spread to the PF Tooltip component

ChatbotHeader

*required
NameTypeDefaultDescription
childrenrequiredReact.ReactNodeContent to be displayed in the chatbot header
classNamestringCustom classname for the header component

ChatbotHeaderMain

*required
NameTypeDefaultDescription
childrenrequiredReact.ReactNodeMenu and/or chatbot header components
classNamestringCustom classname for the header component

ChatbotHeaderMenu

*required
NameTypeDefaultDescription
onMenuTogglerequired() => voidCallback function to attach to menu toggle on top right of chatbot header.
classNamestringCustom classname for the header component
innerRefReact.Ref<HTMLButtonElement>Ref applied to menu
menuAriaLabelstringAria label for menu
tooltipPropsTooltipPropsProps spread to the PF Tooltip component wrapping the display mode dropdown

ChatbotHeaderActions

*required
NameTypeDefaultDescription
childrenrequiredReact.ReactNodeContent to be displayed in the chatbot header
classNamestringCustom classname for the header component

ChatbotHeaderTitle

*required
NameTypeDefaultDescription
childrenReact.ReactNodeContent to be displayed in the chatbot header
classNamestringCustom classname for the header component
displayModeChatbotDisplayModeDisplay mode of chatbot, in case you want to conditionally show a title
showOnDefaultReact.ReactNode | stringContent to display by default; this will be shown if a case is not explicitly set
showOnDockedReact.ReactNode | stringContent to display on docked screen
showOnEmbeddedReact.ReactNode | stringContent to display on overlay screen
showOnFullScreenReact.ReactNode | stringContent to display on full screen

ChatbotHeaderOptionsDropdown

*required
NameTypeDefaultDescription
childrenrequiredReact.ReactNodeContent to be displayed in the chatbot header
classNamestringCustom classname for the header component
menuToggleAriaLabelstring'Chatbot options'Aria label for menu toggle
tooltipPropsTooltipPropsProps spread to the PF Tooltip component wrapping the display mode dropdown

ChatbotHeaderSelectorDropdown

*required
NameTypeDefaultDescription
childrenrequiredReact.ReactNodeContent to be displayed in the chatbot header
valuerequiredstringValue of the selected dropdown item
classNamestringCustom classname for the header component
menuToggleAriaLabelstringAria label for menu toggle
tooltipContentstring'Chatbot selector'Text displayed in Tooltip wrapping the display mode dropdown
tooltipPropsTooltipPropsProps spread to the PF Tooltip component wrapping the display mode dropdown

ChatbotFooter

*required
NameTypeDefaultDescription
childrenReact.ReactNodeChildren for the Footer that supports MessageBar and FootNote components
classNamestringCustom classname for the Footer component

MessageBar

*required
NameTypeDefaultDescription
onSendMessagerequired(message: string) => voidCallback to get the value of input message by user
alwayShowSendButtonbooleanFlag to always to show the send button. By default send button is shown when there is a message in the input field
attachMenuPropsMessageBarWithAttachMenuPropsProps to enable a menu that opens when the Attach button is clicked, instead of the attachment window
buttonProps{ attach?: { tooltipContent?: string; props?: ButtonProps; inputTestId?: string }; stop?: { tooltipContent?: string; props?: ButtonProps }; send?: { tooltipContent?: string; props?: ButtonProps }; microphone?: { tooltipContent?: { active?: string; inactive?: string }; language?: string; props?: ButtonProps; }; }Prop to allow passage of additional props to buttons
classNamestringClass Name for the MessageBar component
handleAttach(data: File[], event: DropEvent) => voidCallback function for when attach button is used to upload a file
handleStopButton(event: React.MouseEvent<HTMLButtonElement>) => voidCallback function for when stop button is clicked
hasAttachButtonbooleantrueFlag to disable/enable the Attach button
hasMicrophoneButtonbooleanFlag to enable the Microphone button
hasStopButtonbooleanFlag to enable the Stop button, used for streaming content
isSendButtonDisabledbooleanFlag to provide manual control over whether send button is disabled
onChange(event: React.ChangeEvent<HTMLDivElement>, value: string) => voidA callback for when the text area value changes.

ChatbotFootnote

*required
NameTypeDefaultDescription
labelrequiredstringLabel to show for the footnote
classNamestringCustom classname for the Footnote component
popoverChatbotFootnotePopoverConfig for the popover which opens up when footnote is clicked

ChatbotFootnotePopover

*required
NameTypeDefaultDescription
descriptionrequiredstringDescription for the Footnote popover
titlerequiredstringTitle for the Footnote popover
bannerImageChatbotFootnotePopoverBannerImageOptional Banner Image that can be shown in the Footnote Popover
ctaChatbotFootnotePopoverCTAOptional CTA button that can be used to trigger an action and close the popover
linkChatbotFootnotePopoverLinkOptional link that can be used to show and external link like **Learn More**
popoverPropsPopoverPropsProps for PF Popover

ChatbotFootnotePopoverCTA

*required
NameTypeDefaultDescription
labelrequiredstringLabel for the CTA
onClickrequired() => voidCallback for the CTA

ChatbotFootnotePopoverBannerImage

*required
NameTypeDefaultDescription
altrequiredstringAlternate text for the banner image
srcrequiredstringSource for the banner image
*required
NameTypeDefaultDescription
labelrequiredstringLabel for the Link
urlrequiredstringURL for the Link

MessageBarWithAttachMenuProps

*required
NameTypeDefaultDescription
attachMenuItemsrequiredReact.ReactNodeItems in menu
isAttachMenuOpenrequiredbooleanFlag to enable whether attach menu is open
onAttachMenuInputChangerequired(value: string) => voidA callback for when the input value in the menu changes.
onAttachMenuToggleClickrequired() => voidA callback for when the attachment menu toggle is clicked
setIsAttachMenuOpenrequired(isOpen: boolean) => voidCallback to close attach menu
attachMenuInputPlaceholderstringPlaceholder for search input
onAttachMenuOnOpenChangeKeysstring[]Keys that trigger onOpenChange, defaults to tab and escape. It is highly recommended to include Escape in the array, while Tab may be omitted if the menu contains non-menu items that are focusable.
onAttachMenuOpenChange(isOpen: boolean) => voidCallback to change the open state of the menu. Triggered by clicking outside of the menu.
onAttachMenuSelect(event?: React.MouseEvent<Element, MouseEvent>, value?: string | number) => voidFunction callback called when user selects item in menu.

SourceDetailsMenuItem

*required
NameTypeDefaultDescription
iconrequiredReact.ReactNodeIcon
namerequiredstringName of source
typestringDescription of source

ChatbotConversationHistoryNav

*required
NameTypeDefaultDescription
conversationsrequiredConversation[] | { [key: string]: Conversation[] }Items shown in conversation history
displayModerequiredChatbotDisplayModeDisplay mode of chatbot
isDrawerOpenrequiredbooleanFlag to indicate whether drawer is open
onDrawerTogglerequired(event: React.KeyboardEvent | React.MouseEvent | React.TransitionEvent) => voidFunction called to toggle drawer
setIsDrawerOpenrequired(bool: boolean) => voidFunction called to close drawer
activeItemIdstring | number
drawerActionsTestIdstring'chatbot-nav-drawer-actions'Custom test id for the drawer actions
drawerContentReact.ReactNodeContent wrapped by conversation history nav
handleTextInputChange(value: string) => voidA callback for when the input value changes. Omit to hide input field
newChatButtonTextstring'New chat'Text shown in blue button
onNewChat() => voidCallback function for when blue button is clicked. Omit to hide blue "new chat button"
onSelectActiveItem(event?: React.MouseEvent, itemId?: string | number) => voidCallback function for when an item is selected
reverseButtonOrderbooleanfalseReverses the order of the drawer action buttons
searchInputAriaLabelstring'Filter menu items'Aria label for search input
searchInputPlaceholderstring'Search...'Placeholder for search input

Conversation

*required
NameTypeDefaultDescription
idrequiredstringConversation id
textrequiredstringConversation
iconReact.ReactNodeConversation icon
labelstringTooltip content and aria-label applied to conversation options dropdown
menuClassNamestringOptional classname applied to conversation options dropdown
menuItemsReact.ReactNodeDropdown items rendered in conversation options dropdown
noIconbooleanFlag for no icon
onSelect(event?: React.MouseEvent, value?: string | number) => voidCallback for when user selects item.