Skip to content

Commit 057b227

Browse files
committed
put_scrollable(): remove horizon_scroll parameter and auto scroll in both directions
1 parent bd22f4a commit 057b227

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

pywebio/html/css/app.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,12 +298,12 @@ details[open]>summary {
298298

299299
/* scrollable widget */
300300
.webio-scrollable{
301-
overflow-y: scroll;
302-
padding: 10px;
301+
overflow: auto;
303302
margin-bottom: 10px;
304303
}
305304

306305
.webio-scrollable.scrollable-border{
306+
padding: 10px;
307307
border: 1px solid rgba(0,0,0,.125);
308308
box-shadow: inset 0 0 2px 0 rgba(0,0,0,.1);
309309
}

pywebio/output.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,7 @@ def put_collapse(title, content=[], open=False, scope=None, position=OutputPosit
10811081

10821082

10831083
@safely_destruct_output_when_exp('content')
1084-
def put_scrollable(content=[], height=400, keep_bottom=False, horizon_scroll=False, border=True,
1084+
def put_scrollable(content=[], height=400, keep_bottom=False, border=True,
10851085
scope=None, position=OutputPosition.BOTTOM, **kwargs) -> Output:
10861086
"""Output a fixed height content area. scroll bar is displayed when the content exceeds the limit
10871087
@@ -1090,8 +1090,8 @@ def put_scrollable(content=[], height=400, keep_bottom=False, horizon_scroll=Fal
10901090
:param int/tuple height: The height of the area (in pixels).
10911091
``height`` parameter also accepts ``(min_height, max_height)`` to indicate the range of height, for example,
10921092
``(100, 200)`` means that the area has a minimum height of 100 pixels and a maximum of 200 pixels.
1093+
Set ``None`` if you don't want to limit the height
10931094
:param bool keep_bottom: Whether to keep the content area scrolled to the bottom when updated.
1094-
:param bool horizon_scroll: Whether to use the horizontal scroll bar
10951095
:param bool border: Whether to show border
10961096
:param int scope, position: Those arguments have the same meaning as for `put_text()`
10971097
@@ -1110,9 +1110,22 @@ def put_scrollable(content=[], height=400, keep_bottom=False, horizon_scroll=Fal
11101110
o.append(time.time())
11111111
time.sleep(0.5)
11121112
1113+
You can use `put_scrollable()` to avoid page width exceeding screen width (especially in mobile device):
1114+
1115+
.. exportable-codeblock::
1116+
:name: put_scrollable_2
1117+
:summary: `put_scrollable()` usage
1118+
1119+
with put_scrollable(border=False, height=None):
1120+
# use `white-space: nowrap` to disable line break
1121+
put_text('long content ' * 20).style('white-space: nowrap')
1122+
11131123
.. versionchanged:: 1.1
11141124
add ``height`` parameter,remove ``max_height`` parameter;
11151125
add ``keep_bottom`` parameter
1126+
1127+
.. versionchanged:: 1.5
1128+
remove ``horizon_scroll`` parameter
11161129
"""
11171130
if not isinstance(content, (list, tuple, OutputList)):
11181131
content = [content]
@@ -1131,9 +1144,8 @@ def put_scrollable(content=[], height=400, keep_bottom=False, horizon_scroll=Fal
11311144
min_height, max_height = height, height
11321145

11331146
spec = _get_output_spec('scrollable', contents=content, min_height=min_height, max_height=max_height,
1134-
keep_bottom=keep_bottom, horizon_scroll=horizon_scroll, border=border, scope=scope,
1135-
position=position)
1136-
return Output(spec)
1147+
keep_bottom=keep_bottom, border=border, scope=scope, position=position)
1148+
return Output(spec).enable_context_manager(container_selector='> div')
11371149

11381150

11391151
@safely_destruct_output_when_exp('tabs')

webiojs/src/models/output.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ let TabsWidget = {
202202

203203
const SCROLLABLE_TPL = `<div>
204204
<div class="webio-scrollable{{#border}} scrollable-border{{/border}}" {{#keep_bottom}}tabindex="0"{{/keep_bottom}}
205-
style="min-height: {{min_height}}px; max-height: {{max_height}}px;{{#horizon_scroll}}overflow-x: scroll;{{/horizon_scroll}}">
205+
style="{{#min_height}}min-height: {{min_height}}px;{{/min_height}} {{#max_height}}max-height: {{max_height}}px;{{/max_height}}">
206206
{{#contents}}
207207
{{& pywebio_output_parse}}
208208
{{/contents}}
@@ -212,9 +212,7 @@ const SCROLLABLE_TPL = `<div>
212212
let ScrollableWidget = {
213213
handle_type: 'scrollable',
214214
get_element: function (spec: {
215-
contents: any, min_height: string,
216-
max_height: string, keep_bottom: boolean,
217-
horizon_scroll: boolean, border: boolean
215+
contents: any, min_height: string, max_height: string, keep_bottom: boolean, border: boolean
218216
}) {
219217
let elem = render_tpl(SCROLLABLE_TPL, spec);
220218
let container = elem.find('> div');

0 commit comments

Comments
 (0)