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

Fix dynamically updating description tooltips #6676

Merged
merged 3 commits into from
Apr 5, 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
16 changes: 16 additions & 0 deletions panel/models/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ export class ButtonView extends BkButtonView {
}
}

override connect_signals(): void {
super.connect_signals()
const {tooltip} = this.model.properties
this.on_change(tooltip, () => this.update_tooltip())
}

async update_tooltip(): Promise<void> {
if (this.tooltip != null) {
this.tooltip.remove()
}
const {tooltip} = this.model
if (tooltip != null) {
this.tooltip = await build_view(tooltip, {parent: this})
}
}

override async lazy_initialize(): Promise<void> {
await super.lazy_initialize()
const {tooltip} = this.model
Expand Down
16 changes: 16 additions & 0 deletions panel/models/checkbox_button_group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@ export class CheckboxButtonGroupView extends bkCheckboxButtonGroupView {
}
}

override connect_signals(): void {
super.connect_signals()
const {tooltip} = this.model.properties
this.on_change(tooltip, () => this.update_tooltip())
}

async update_tooltip(): Promise<void> {
if (this.tooltip != null) {
this.tooltip.remove()
}
const {tooltip} = this.model
if (tooltip != null) {
this.tooltip = await build_view(tooltip, {parent: this})
}
}

override async lazy_initialize(): Promise<void> {
await super.lazy_initialize()
const {tooltip} = this.model
Expand Down
13 changes: 12 additions & 1 deletion panel/models/icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,22 @@ export class ClickableIconView extends ControlView {

override connect_signals(): void {
super.connect_signals()
const {icon, active_icon, disabled, value, size} = this.model.properties
const {icon, active_icon, disabled, value, size, tooltip} = this.model.properties
this.on_change([active_icon, icon, value], () => this.update_icon())
this.on_change(this.model.properties.title, () => this.update_label())
this.on_change(disabled, () => this.update_cursor())
this.on_change(size, () => this.update_size())
this.on_change(tooltip, () => this.update_tooltip())
}

async update_tooltip(): Promise<void> {
if (this.tooltip != null) {
this.tooltip.remove()
}
const {tooltip} = this.model
if (tooltip != null) {
this.tooltip = await build_view(tooltip, {parent: this})
}
}

override render(): void {
Expand Down
16 changes: 16 additions & 0 deletions panel/models/radio_button_group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@ export class RadioButtonGroupView extends bkRadioButtonGroupView {
}
}

override connect_signals(): void {
super.connect_signals()
const {tooltip} = this.model.properties
this.on_change(tooltip, () => this.update_tooltip())
}

async update_tooltip(): Promise<void> {
if (this.tooltip != null) {
this.tooltip.remove()
}
const {tooltip} = this.model
if (tooltip != null) {
this.tooltip = await build_view(tooltip, {parent: this})
}
}

override async lazy_initialize(): Promise<void> {
await super.lazy_initialize()
const {tooltip} = this.model
Expand Down
13 changes: 13 additions & 0 deletions panel/tests/ui/widgets/test_icon.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,16 @@ def test_button_icon_name_dynamically(page):
button.size = "2em"
# check size
assert page.locator(".bk-IconLabel").bounding_box()["width"] >= 40


def test_button_icon_description_dynamically(page):
button = ButtonIcon(description="Like")
serve_component(page, button)

assert button.description == "Like"
page.locator(".bk-TablerIcon").click()
assert page.locator(".bk-tooltip-content").text_content() == "Like"

button.description = "Dislike"
page.locator(".bk-TablerIcon").click()
assert page.locator(".bk-tooltip-content").text_content() == "Dislike"
Loading