@@ -1067,6 +1067,7 @@ def put_scrollable(content=[], height=400, keep_bottom=False, horizon_scroll=Fal
10671067 :param int/tuple height: The height of the area (in pixels).
10681068 ``height`` parameter also accepts ``(min_height, max_height)`` to indicate the range of height, for example,
10691069 ``(100, 200)`` means that the area has a minimum height of 100 pixels and a maximum of 200 pixels.
1070+ :param bool keep_bottom: Whether to keep the content area scrolled to the bottom when updated.
10701071 :param bool horizon_scroll: Whether to use the horizontal scroll bar
10711072 :param bool border: Whether to show border
10721073 :param int scope, position: Those arguments have the same meaning as for `put_text()`
@@ -1106,41 +1107,10 @@ def put_scrollable(content=[], height=400, keep_bottom=False, horizon_scroll=Fal
11061107 except Exception :
11071108 min_height , max_height = height , height
11081109
1109- dom_id = 'pywebio-%s' % random_str (10 )
1110-
1111- tpl = """<div id="{{dom_id}}" {{#keep_bottom}}tabindex="0"{{/keep_bottom}}
1112- style="min-height: {{min_height}}px; max-height: {{max_height}}px;
1113- overflow-y: scroll;
1114- {{#horizon_scroll}}overflow-x: scroll;{{/horizon_scroll}}
1115- {{#border}}
1116- border: 1px solid rgba(0,0,0,.125);
1117- box-shadow: inset 0 0 2px 0 rgba(0,0,0,.1);
1118- {{/border}}
1119- padding: 10px;
1120- margin-bottom: 10px;">
1121-
1122- {{#contents}}
1123- {{& pywebio_output_parse}}
1124- {{/contents}}
1125- </div>"""
1126- if keep_bottom :
1127- tpl += """
1128- <script>
1129- (function(){
1130- let div = document.getElementById(%r), stop=false;
1131- $(div).on('focusin', function(e){ stop=true }).on('focusout', function(e){ stop=false });;
1132- new MutationObserver(function (mutations, observe) {
1133- if(!stop) $(div).stop().animate({ scrollTop: $(div).prop("scrollHeight")}, 200);
1134- }).observe(div, { childList: true, subtree:true });
1135- })();
1136- </script>
1137- """ % dom_id
1138-
1139- return put_widget (template = tpl ,
1140- data = dict (dom_id = dom_id , contents = content , min_height = min_height ,
1141- max_height = max_height , keep_bottom = keep_bottom ,
1142- horizon_scroll = horizon_scroll , border = border ),
1143- scope = scope , position = position ).enable_context_manager ()
1110+ spec = _get_output_spec ('scrollable' , contents = content , min_height = min_height , max_height = max_height ,
1111+ keep_bottom = keep_bottom , horizon_scroll = horizon_scroll , border = border , scope = scope ,
1112+ position = position )
1113+ return Output (spec )
11441114
11451115
11461116@safely_destruct_output_when_exp ('tabs' )
0 commit comments