Skip to content

Commit 9d459ce

Browse files
committed
Allow for auto-scrolling to be disabled
1 parent 7c0a536 commit 9d459ce

File tree

4 files changed

+37
-21
lines changed

4 files changed

+37
-21
lines changed

js/markdown-stream/markdown-stream.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,12 @@ function contentToHTML(content: string, content_type: ContentType) {
7373

7474
class MarkdownElement extends LightElement {
7575
@property() content = "";
76-
@property() content_type: ContentType = "markdown";
77-
@property({ type: Boolean, reflect: true }) streaming = false;
76+
@property({ attribute: "content-type" })
77+
content_type: ContentType = "markdown";
78+
@property({ type: Boolean, reflect: true })
79+
streaming = false;
80+
@property({ type: Boolean, reflect: true, attribute: "auto-scroll" })
81+
auto_scroll = false;
7882

7983
render() {
8084
return html`${contentToHTML(this.content, this.content_type)}`;
@@ -185,6 +189,8 @@ class MarkdownElement extends LightElement {
185189
}
186190

187191
#findScrollableParent(): HTMLElement | null {
192+
if (!this.auto_scroll) return null;
193+
188194
// eslint-disable-next-line
189195
let el: HTMLElement | null = this;
190196
while (el) {

shiny/ui/_markdown_stream.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ def ui(
8787
*,
8888
content: str = "",
8989
content_type: StreamingContentType = "markdown",
90+
auto_scroll: bool = True,
9091
width: CssUnit = "100%",
9192
height: CssUnit = "auto",
9293
) -> Tag:
@@ -107,6 +108,9 @@ def ui(
107108
- `"html"`: for rendering HTML content.
108109
- `"text"`: for plain text.
109110
- `"semi-markdown"`: for rendering markdown, but with HTML tags escaped.
111+
auto_scroll
112+
Whether to automatically scroll to the bottom of a scrollable container
113+
when new content is added. Default is True.
110114
width
111115
The width of the markdown stream container.
112116
height
@@ -121,6 +125,7 @@ def ui(
121125
self.id,
122126
content=content,
123127
content_type=content_type,
128+
auto_scroll=auto_scroll,
124129
width=width,
125130
height=height,
126131
)
@@ -212,6 +217,7 @@ def markdown_stream_ui(
212217
*,
213218
content: str = "",
214219
content_type: StreamingContentType = "markdown",
220+
auto_scroll: bool = True,
215221
width: CssUnit = "100%",
216222
height: CssUnit = "auto",
217223
) -> Tag:
@@ -233,6 +239,9 @@ def markdown_stream_ui(
233239
- `"html"`: for rendering HTML content.
234240
- `"text"`: for plain text.
235241
- `"semi-markdown"`: for rendering markdown, but with HTML tags escaped.
242+
auto_scroll
243+
Whether to automatically scroll to the bottom of a scrollable container
244+
when new content is added. Default is True.
236245
width
237246
The width of the markdown stream container.
238247
height
@@ -245,9 +254,10 @@ def markdown_stream_ui(
245254
"style": css(
246255
width=as_css_unit(width),
247256
height=as_css_unit(height),
248-
)
257+
),
258+
"content-type": content_type,
259+
"auto-scroll": "" if auto_scroll else None,
249260
},
250261
id=id,
251262
content=content,
252-
content_type=content_type,
253263
)

shiny/www/py-shiny/markdown-stream/markdown-stream.js

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

shiny/www/py-shiny/markdown-stream/markdown-stream.js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)