diff --git a/panel/layout/flex.py b/panel/layout/flex.py index ef26d38eeb..b1f2e0515c 100644 --- a/panel/layout/flex.py +++ b/panel/layout/flex.py @@ -2,6 +2,8 @@ import param +from param.parameterized import iscoroutinefunction, resolve_ref + from ..reactive import ReactiveHTML from .base import ListLike @@ -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): """ diff --git a/panel/tests/layout/test_base.py b/panel/tests/layout/test_base.py index 455ab9c301..f4bfb6c60e 100644 --- a/panel/tests/layout/test_base.py +++ b/panel/tests/layout/test_base.py @@ -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 @@ -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"]: @@ -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