From fbeda4a80b5cc3d16761234b994d6b552b0565b4 Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Sun, 14 Jan 2024 13:00:49 +0100 Subject: [PATCH 1/2] Add resize handler for FloatPanel --- panel/layout/float.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/panel/layout/float.py b/panel/layout/float.py index e1300a46bf..0c5f359bdb 100644 --- a/panel/layout/float.py +++ b/panel/layout/float.py @@ -106,8 +106,14 @@ class FloatPanel(ListLike, ReactiveHTML): config = {...config, ...data.config} state.panel = jsPanel.create(config); if (data.status !== 'normalized') { - view.run_script('status') + view.run_script('status') } + state.resizeHandler = (event) => { + if (event.panel === state.panel) { + view.invalidate_layout() + } + } + document.addEventListener('jspanelresizestop', state.resizeHandler, false) """, "name": "state.panel.setHeaderTitle(data.name)", "status": """ @@ -138,7 +144,11 @@ class FloatPanel(ListLike, ReactiveHTML): """, "contained": "delete state.panel; view.invalidate_render();", "theme": "state.panel.setTheme(data.theme)", - "remove": "view.run_script('close'); state.panel = undefined;", + "remove": """ + document.removeEventListener('jspanelresizestop', state.resizeHandler, false); + view.run_script('close'); + state.panel = undefined; + """, "offsetx": "view.run_script('reposition')", "offsety": "view.run_script('reposition')", "position": "if (!data.contained) { view.run_script('reposition') }", From b8372865adad905f0cdb83a52ed37d44f087b737 Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Sun, 14 Jan 2024 13:18:29 +0100 Subject: [PATCH 2/2] Add test --- panel/tests/ui/layout/test_floatpanel.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/panel/tests/ui/layout/test_floatpanel.py b/panel/tests/ui/layout/test_floatpanel.py index cc834bcca5..a84afc7907 100644 --- a/panel/tests/ui/layout/test_floatpanel.py +++ b/panel/tests/ui/layout/test_floatpanel.py @@ -1,6 +1,6 @@ import pytest -from panel import FloatPanel, Spacer +from panel import FloatPanel, Row, Spacer from panel.tests.util import serve_component, wait_until pytestmark = pytest.mark.ui @@ -32,3 +32,22 @@ def test_float_panel_status_set_on_init(page): wait_until(lambda: ( float_container.bounding_box()['y'] + float_container.bounding_box()['height'] ) == page.viewport_size['height'], page) + +def test_float_panel_resize(page): + float_panel = FloatPanel( + Row( + Spacer(styles=dict(background='red'), css_classes=['red'], height=200, sizing_mode='stretch_width'), + Spacer(styles=dict(background='green'), css_classes=['green'], height=200, sizing_mode='stretch_width'), + Spacer(styles=dict(background='blue'), css_classes=['blue'], height=200, sizing_mode='stretch_width'), + ) + ) + + serve_component(page, float_panel) + + resize_handle = page.locator('.jsPanel-resizeit-se') + + resize_handle.drag_to(resize_handle, target_position={'x': 510, 'y': 300}, force=True) + + wait_until(lambda: int(page.locator('.red').bounding_box()['width']) == 200, page) + wait_until(lambda: int(page.locator('.green').bounding_box()['width']) == 200, page) + wait_until(lambda: int(page.locator('.blue').bounding_box()['width']) == 200, page)