Update pages/type_text.py
Browse files- pages/type_text.py +34 -21
pages/type_text.py
CHANGED
@@ -28,17 +28,36 @@ def scrollToBottom():
|
|
28 |
# JavaScript to scroll to bottom
|
29 |
JS_code = """
|
30 |
<script>
|
31 |
-
// Function to scroll to the bottom of
|
32 |
function scrollToBottom() {
|
33 |
-
console.log("
|
34 |
-
|
35 |
-
//
|
36 |
-
//
|
37 |
-
//
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
}
|
43 |
|
44 |
// --- Logic for handling dynamically added content ---
|
@@ -47,27 +66,21 @@ def scrollToBottom():
|
|
47 |
// This observer will watch for changes in the DOM.
|
48 |
const observer = new MutationObserver(function(mutations) {
|
49 |
console.log("MutationObserver detected changes."); // Log when observer fires
|
50 |
-
// We don't need to inspect the mutations array in detail for this case.
|
51 |
-
// Any significant change in the body's content (like new elements being added by Streamlit)
|
52 |
-
// should trigger a scroll to the bottom.
|
53 |
-
|
54 |
// Use requestAnimationFrame to ensure the scroll happens after the browser
|
55 |
-
// has potentially rendered the new content.
|
56 |
requestAnimationFrame(scrollToBottom);
|
57 |
});
|
58 |
|
59 |
// Configure the observer to watch for changes to the child list of the body element.
|
60 |
-
//
|
61 |
-
|
|
|
62 |
|
63 |
console.log("Starting MutationObserver on document.body."); // Log when observer starts
|
64 |
// Start observing the document body for the configured mutations.
|
65 |
-
// This will start the auto-scrolling whenever Streamlit adds new content to the page.
|
66 |
observer.observe(document.body, config);
|
67 |
|
68 |
-
// --- Initial scroll on page load
|
69 |
-
// You might still want an initial scroll when the page first loads,
|
70 |
-
// in case there's content already present.
|
71 |
window.addEventListener('load', function() {
|
72 |
console.log("Window loaded. Initial scroll attempt."); // Log on window load
|
73 |
requestAnimationFrame(scrollToBottom);
|
|
|
28 |
# JavaScript to scroll to bottom
|
29 |
JS_code = """
|
30 |
<script>
|
31 |
+
// Function to scroll to the bottom of a specific container
|
32 |
function scrollToBottom() {
|
33 |
+
console.log("Attempting to scroll container to bottom."); // Log when scroll function is called
|
34 |
+
|
35 |
+
// --- Identify the scrollable container ---
|
36 |
+
// Streamlit often uses a main container div. We'll try to find it.
|
37 |
+
// You might need to inspect your deployed app's HTML to find the correct selector
|
38 |
+
// for the element that actually has the scrollbar.
|
39 |
+
// Common candidates:
|
40 |
+
// - Elements with classes like 'stAppViewContainer', 'main', 'block-container'
|
41 |
+
// - A div directly containing your dynamic content
|
42 |
+
|
43 |
+
// Let's try a common Streamlit container class. You might need to adjust this.
|
44 |
+
const scrollableContainer = document.querySelector('.stAppViewContainer'); // Example selector
|
45 |
+
|
46 |
+
if (scrollableContainer) {
|
47 |
+
console.log("Scrollable container found. Scrolling...");
|
48 |
+
// Scroll the found container to its bottom
|
49 |
+
scrollableContainer.scrollTo({
|
50 |
+
top: scrollableContainer.scrollHeight,
|
51 |
+
behavior: 'smooth'
|
52 |
+
});
|
53 |
+
} else {
|
54 |
+
console.warn("Scrollable container not found. Falling back to document.body scroll.");
|
55 |
+
// Fallback to body scroll if the specific container isn't found
|
56 |
+
window.scrollTo({
|
57 |
+
top: document.body.scrollHeight,
|
58 |
+
behavior: 'smooth'
|
59 |
+
});
|
60 |
+
}
|
61 |
}
|
62 |
|
63 |
// --- Logic for handling dynamically added content ---
|
|
|
66 |
// This observer will watch for changes in the DOM.
|
67 |
const observer = new MutationObserver(function(mutations) {
|
68 |
console.log("MutationObserver detected changes."); // Log when observer fires
|
|
|
|
|
|
|
|
|
69 |
// Use requestAnimationFrame to ensure the scroll happens after the browser
|
70 |
+
// has potentially rendered the new content.
|
71 |
requestAnimationFrame(scrollToBottom);
|
72 |
});
|
73 |
|
74 |
// Configure the observer to watch for changes to the child list of the body element.
|
75 |
+
// We keep observing the body because Streamlit adds content there,
|
76 |
+
// even if a child element is the one that scrolls.
|
77 |
+
const config = { childList: true, subtree: true };
|
78 |
|
79 |
console.log("Starting MutationObserver on document.body."); // Log when observer starts
|
80 |
// Start observing the document body for the configured mutations.
|
|
|
81 |
observer.observe(document.body, config);
|
82 |
|
83 |
+
// --- Initial scroll on page load ---
|
|
|
|
|
84 |
window.addEventListener('load', function() {
|
85 |
console.log("Window loaded. Initial scroll attempt."); // Log on window load
|
86 |
requestAnimationFrame(scrollToBottom);
|