Skip to content

Commit

Permalink
Ensure FileDownload label text updates correctly (#7489)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr authored Nov 13, 2024
1 parent cd645dd commit 9766b6b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
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

0 comments on commit 9766b6b

Please sign in to comment.