Skip to content

Commit 1ddd82c

Browse files
committed
chore(SkipToContent): Add direct example
1 parent c5830f5 commit 1ddd82c

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import ChatbotContent from '@patternfly/virtual-assistant/dist/dynamic/ChatbotCo
2525
import ChatbotWelcomePrompt from '@patternfly/virtual-assistant/dist/dynamic/ChatbotWelcomePrompt';
2626
import MessageBox from '@patternfly/virtual-assistant/dist/dynamic/MessageBox';
2727
import Message from '@patternfly/virtual-assistant/dist/dynamic/Message';
28+
import ChatbotToggle from '@patternfly/virtual-assistant/dist/dynamic/ChatbotToggle';
2829

2930
### Container
3031

@@ -71,3 +72,11 @@ To provide users with a more specific direction, you can also include optional w
7172
```js file="./ChatbotWelcomePrompt.tsx"
7273

7374
```
75+
76+
### Skip to content
77+
78+
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. The [PatternFly skip to content component](/components/skip-to-content) can be used for this purpose. To display this button, you must tab into the main window. We recommend putting focus on the toggle if the chatbot is closed, and the chatbot when it is open.
79+
80+
```js file="./SkipToContent.tsx" isFullscreen
81+
82+
```
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React from 'react';
2+
3+
import { SkipToContent } from '@patternfly/react-core';
4+
import ChatbotToggle from '@patternfly/virtual-assistant/dist/dynamic/ChatbotToggle';
5+
import Chatbot, { ChatbotDisplayMode } from '@patternfly/virtual-assistant/dist/dynamic/Chatbot';
6+
7+
export const ChatbotDemo: React.FunctionComponent = () => {
8+
const [chatbotVisible, setChatbotVisible] = React.useState<boolean>(true);
9+
const toggleRef = React.useRef<HTMLButtonElement>(null);
10+
const chatbotRef = React.useRef<HTMLDivElement>(null);
11+
const displayMode = ChatbotDisplayMode.default;
12+
13+
const handleSkipToContent = (e) => {
14+
e.preventDefault();
15+
if (!chatbotVisible && toggleRef.current) {
16+
toggleRef.current.focus();
17+
}
18+
if (chatbotVisible && chatbotRef.current) {
19+
chatbotRef.current.focus();
20+
}
21+
};
22+
23+
return (
24+
<>
25+
<SkipToContent onClick={handleSkipToContent} href="#">
26+
Skip to chatbot
27+
</SkipToContent>
28+
<ChatbotToggle
29+
toolTipLabel="Chatbot"
30+
isChatbotVisible={chatbotVisible}
31+
onToggleChatbot={() => setChatbotVisible(!chatbotVisible)}
32+
id="chatbot-toggle"
33+
ref={toggleRef}
34+
/>
35+
<Chatbot isVisible={chatbotVisible} displayMode={displayMode} ref={chatbotRef}>
36+
&nbsp;
37+
</Chatbot>
38+
</>
39+
);
40+
};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ This demo displays a basic chatbot, which includes:
7777

7878
6. A [`<ChatbotConversationHistoryNav>`](/patternfly-ai/chatbot/chatbot-conversation-history) toggled open and closed by the `<ChatbotHeaderMenu`> in the `<ChatbotHeader>`.
7979

80-
7. A "skip to chatbot" button that allows you to skip to the end of the chatbot content via the [PatternFly skip to content component](/components/skip-to-content). To display this button you must tab into the main window.
80+
7. A "skip to chatbot" button that allows you to skip to the chatbot content via the [PatternFly skip to content component](/components/skip-to-content). To display this button you must tab into the main window.
8181

8282
```js file="./Chatbot.tsx" isFullscreen
8383

packages/module/src/Chatbot/Chatbot.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ html.pf-chatbot-allow--docked {
7070
}
7171

7272
.pf-chatbot-container {
73+
height: 100%;
74+
width: 100%;
7375
// Hide chatbot
7476
&--hidden {
7577
pointer-events: none;

0 commit comments

Comments
 (0)