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 resize handler for FloatPanel #6201

Merged
merged 2 commits into from
Jan 14, 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
14 changes: 12 additions & 2 deletions panel/layout/float.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": """
Expand Down Expand Up @@ -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') }",
Expand Down
21 changes: 20 additions & 1 deletion panel/tests/ui/layout/test_floatpanel.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)