Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for passing objects reference to FlexBox #6387

Merged
merged 4 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion panel/layout/flex.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import param

from param.parameterized import iscoroutinefunction, resolve_ref

from ..reactive import ReactiveHTML
from .base import ListLike

Expand Down Expand Up @@ -60,13 +62,24 @@ class FlexBox(ListLike, ReactiveHTML):
_template = (Path(__file__).parent / 'flexbox.html').read_text('utf-8')

def __init__(self, *objects, **params):
from ..pane.base import panel
if 'sizing_mode' not in params:
direction = params.get('flex_direction', self.flex_direction)
if direction.startswith('row'):
params['sizing_mode'] = 'stretch_width'
else:
params['sizing_mode'] = 'stretch_height'
super().__init__(objects=list(objects), **params)
if objects:
if 'objects' in params:
raise ValueError("A %s's objects should be supplied either "
"as positional arguments or as a keyword, "
"not both." % type(self).__name__)
params['objects'] = [panel(pane) for pane in objects]
elif 'objects' in params:
objects = params['objects']
if not resolve_ref(objects) or iscoroutinefunction(objects):
params['objects'] = [panel(pane) for pane in objects]
super().__init__(**params)

def select(self, selector=None):
"""
Expand Down
8 changes: 4 additions & 4 deletions panel/tests/layout/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from panel.chat import ChatInterface
from panel.layout import (
Accordion, Card, Column, Row, Spacer, Tabs, WidgetBox,
Accordion, Card, Column, FlexBox, Row, Spacer, Tabs, WidgetBox,
)
from panel.layout.base import ListPanel, NamedListPanel
from panel.pane import Bokeh, Markdown
Expand Down Expand Up @@ -569,7 +569,6 @@ def test_no_expand_fixed(panel, document, comm):

assert model.sizing_mode == 'fixed'


@pytest.mark.parametrize('scroll_param', ["auto_scroll_limit", "scroll", "scroll_button_threshold", "view_latest"])
def test_column_scroll_params_sets_scroll(scroll_param, document, comm):
if scroll_param not in ["auto_scroll_limit", "scroll_button_threshold"]:
Expand All @@ -580,9 +579,10 @@ def test_column_scroll_params_sets_scroll(scroll_param, document, comm):
assert getattr(col, scroll_param)
assert col.scroll

def test_pass_objects_ref(document, comm):
@pytest.mark.parametrize('layout', [Row, Column, FlexBox])
def test_pass_objects_ref(document, comm, layout):
multi_select = MultiSelect(options=['foo', 'bar', 'baz'], value=['bar', 'baz'])
col = Column(objects=multi_select)
col = layout(objects=multi_select)
col.get_root(document, comm=comm)

assert len(col.objects) == 2
Expand Down
Loading