Skip to content

Commit b130ad2

Browse files
feat(MessageBox): Implement Smart Scroll (#550)
Introduces an optional enableSmartScroll feature, which provides a smooth and user-friendly experience when interacting with dynamically updated content. The feature pauses scrolling when the user scrolls up and resumes when the user scrolls down or clicks the "back to bottom" button. Imperative methods (scrollToTop, scrollToBottom, are isSmartScrollActive) are exposed via ref to provide programmatic control over the scrolling behavior. The component will not scroll automatically unless the user scrolls to the bottom or uses the exposed methods. The user has full control over the scroll position. The scroll trigger (such as the number of messages) can also be modified.
1 parent a0d169f commit b130ad2

File tree

5 files changed

+1121
-96
lines changed

5 files changed

+1121
-96
lines changed

packages/module/patternfly-docs/content/extensions/chatbot/examples/demos/AttachmentDemos.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ import PFIconLogoReverse from '../UI/PF-IconLogo-Reverse.svg';
4545
import userAvatar from '../Messages/user_avatar.svg';
4646
import patternflyAvatar from '../Messages/patternfly_avatar.jpg';
4747
import { FunctionComponent, useState, useRef, isValidElement, cloneElement, Children, ReactNode, MouseEvent } from 'react';
48+
import { getTrackingProviders } from "@patternfly/chatbot/dist/dynamic/tracking";
49+
import ChatbotConversationHistoryNav from '@patternfly/chatbot/dist/dynamic/ChatbotConversationHistoryNav';
4850

4951
## Demos
5052

@@ -62,6 +64,40 @@ It is also important to announce when new content appears onscreen for accessibi
6264

6365
```
6466

67+
### Message auto-scrolling
68+
69+
This demo shows auto-scrolling functionality, which automatically scrolls to the bottom of the active chat.
70+
71+
To enable auto-scroll behavior pass the `enableSmartScroll` prop to the [`<MessageBox>`](/patternfly-ai/chatbot/ui#message-box) component.
72+
73+
When enabled:
74+
75+
- Scroll position is automatically managed based on user interaction.
76+
- Scrolling is _not_ forced to the bottom when new messages arrive, unless explicitly triggered via the `scrollToBottom()` method.
77+
- If the user scrolls up or interacts with UI controls like "Back to top" or "Back to bottom", the component pauses auto-scroll to respect user intent.
78+
- Auto-scroll resumes only when the user scrolls back down manually or programmatically via the `scrollToBottom({resumeSmartScroll: true})` method.
79+
80+
#### Imperative methods via `ref`
81+
82+
When using `ref`, the `<MessageBox>` component exposes the following methods:
83+
84+
- `scrollToBottom()`: Scrolls to the bottom of the message container.
85+
- `scrollToTop()`: Scrolls to the top of the message container.
86+
- `isSmartScrollActive()`: Returns `true` if smart auto-scroll is currently active.
87+
- Native `HTMLDivElement` methods like `scrollTo()`.
88+
89+
This demo includes broader ChatBot features, including:
90+
91+
1. A [`<ChatbotToggle>`](/patternfly-ai/chatbot/ui#toggle) that controls the [`<Chatbot>`](/patternfly-ai/chatbot/ui#container) container.
92+
2. A `<ChatbotContent>` and [`<MessageBox>`](/patternfly-ai/chatbot/ui#content-and-message-box) with:
93+
- A `<ChatbotWelcomePrompt>`
94+
- An initial user message and initial bot message
95+
3. A [`<ChatbotFooter>`](/patternfly-ai/chatbot/ui#footer) with a [`<ChatbotFootnote>`](/patternfly-ai/chatbot/ui#footnote-with-popover) and a `<MessageBar>`
96+
97+
```js file="./ChatbotScrolling.tsx" isFullscreen
98+
99+
```
100+
65101
### Attach via upload button in message bar
66102

67103
This demo displays unique attachment features, including:

0 commit comments

Comments
 (0)