From 9766b6b38abfc1f8c107c5d0d443347265c1c4b5 Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Wed, 13 Nov 2024 16:37:03 +0100 Subject: [PATCH] Ensure FileDownload label text updates correctly (#7489) --- panel/models/file_download.ts | 7 ++++--- panel/tests/ui/widgets/test_misc.py | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/panel/models/file_download.ts b/panel/models/file_download.ts index 210964cc92..993225ad94 100644 --- a/panel/models/file_download.ts +++ b/panel/models/file_download.ts @@ -38,6 +38,7 @@ export class FileDownloadView extends InputWidgetView { anchor_el: HTMLAnchorElement button_el: HTMLButtonElement + label_el: Text declare input_el: HTMLInputElement // HACK: So this.input_el.id = "input" can be set in Bokeh 3.4 _downloadable: boolean = false _click_listener: any @@ -101,8 +102,9 @@ export class FileDownloadView extends InputWidgetView { this.anchor_el.appendChild(separator) this.icon_view.render() } + this.label_el = document.createTextNode(this.model.label) + this.anchor_el.appendChild(this.label_el) this._update_button_style() - this._update_label() // Changing the disabled property calls render() so it needs to be handled here. // This callback is inherited from ControlView in bokehjs. @@ -201,8 +203,7 @@ export class FileDownloadView extends InputWidgetView { } _update_label(): void { - const label = document.createTextNode(this.model.label) - this.anchor_el.appendChild(label) + this.label_el.data = this.model.label } _update_button_style(): void { diff --git a/panel/tests/ui/widgets/test_misc.py b/panel/tests/ui/widgets/test_misc.py index 526e77bf85..f8807c907a 100644 --- a/panel/tests/ui/widgets/test_misc.py +++ b/panel/tests/ui/widgets/test_misc.py @@ -5,6 +5,10 @@ import param import pytest +pytest.importorskip("playwright") + +from playwright.sync_api import expect + from panel.layout import Column, Tabs from panel.tests.util import serve_component from panel.widgets import FileDownload, TextInput @@ -13,6 +17,18 @@ not_windows = pytest.mark.skipif(sys.platform=='win32', reason="Does not work on Windows") +def test_file_download_label_updates(page): + + download = FileDownload(filename='f.txt', embed=False, callback=lambda: io.StringIO()) + + serve_component(page, download) + + expect(page.locator('.bk-btn a')).to_have_text('Download f.txt') + + download.filename = 'g.txt' + + expect(page.locator('.bk-btn a')).to_have_text('Download g.txt') + @not_windows def test_file_download_updates_when_navigating_between_dynamic_tabs(page): text_input = TextInput(value='abc')