From f0dc3de172f6d76a4a9451fd4e2ea3b65208eefc Mon Sep 17 00:00:00 2001 From: martinRenou Date: Mon, 18 Oct 2021 17:03:59 +0200 Subject: [PATCH] Disable toolbar if there is no comm --- src/toolbar_widget.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/toolbar_widget.ts b/src/toolbar_widget.ts index 42651457..0acf3577 100644 --- a/src/toolbar_widget.ts +++ b/src/toolbar_widget.ts @@ -25,6 +25,13 @@ export class ToolbarView extends DOMWidgetView { toggle_button: HTMLButtonElement; toolbar: HTMLDivElement; buttons: { [index: string]: HTMLButtonElement }; + + initialize(parameters: any) { + super.initialize(parameters); + + this.once('comm_live_update', this.update_disabled.bind(this)); + } + render(): void { this.el.classList.add( 'jupyter-widgets', @@ -91,6 +98,7 @@ export class ToolbarView extends DOMWidgetView { const icon = document.createElement('i'); icon.classList.add('center', 'fa', 'fa-fw', 'fa-' + image); button.appendChild(icon); + button.disabled = this.disabled; this.buttons[method_name] = button; @@ -102,6 +110,18 @@ export class ToolbarView extends DOMWidgetView { this.set_buttons_style(); } + get disabled(): boolean { + return !this.model.comm_live; + } + + update_disabled(): void { + for (const name in this.buttons) { + const button = this.buttons[name]; + + button.disabled = this.disabled; + } + } + set_orientation(el: HTMLElement): void { const orientation = this.model.get('orientation'); if (orientation === 'vertical') {