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

Ensure FileDownload label text updates correctly #7489

Merged
merged 1 commit into from
Nov 13, 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
7 changes: 4 additions & 3 deletions panel/models/file_download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down
16 changes: 16 additions & 0 deletions panel/tests/ui/widgets/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')
Expand Down
Loading