Skip to content

Commit

Permalink
Disable toolbar if there is no comm
Browse files Browse the repository at this point in the history
  • Loading branch information
martinRenou committed Oct 19, 2021
1 parent 6d2c1bc commit fe839ef
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/toolbar_widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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;

Expand All @@ -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') {
Expand Down

0 comments on commit fe839ef

Please sign in to comment.