Skip to content

Commit

Permalink
Simplify tooltips to work everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Fleming committed Sep 10, 2024
1 parent 3e49c8e commit 7fa9cba
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 40 deletions.
12 changes: 4 additions & 8 deletions packages/base/src/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1101,18 +1101,14 @@ export class DOMWidgetView extends WidgetView {
}

updateTooltip(): void {
const title = this.tooltip;
if (!title) {
this.el.removeAttribute('title');
} else if (!this.model.get('description')) {
const title = this.model.get('tooltip') ?? this.model.get('description');
if (title) {
this.el.setAttribute('title', title);
} else {
this.el.removeAttribute('title');
}
}

get tooltip() {
return this.model.get('tooltip') ?? this.model.get('description');
}

/**
* Update the DOM classes applied to an element, default to this.el.
*/
Expand Down
8 changes: 0 additions & 8 deletions packages/controls/src/widget_bool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,6 @@ export class CheckboxView extends DescriptionView {
}
}

updateTooltip(): void {
super.updateTooltip();
if (!this.checkbox) return; // we might be constructing the parent
const title = this.tooltip;
this.checkbox.setAttribute('title', title);
this.descriptionSpan.setAttribute('title', title);
}

events(): { [e: string]: string } {
return {
'click input[type="checkbox"]': '_handle_click',
Expand Down
6 changes: 0 additions & 6 deletions packages/controls/src/widget_description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,6 @@ export class DescriptionView extends DOMWidgetView {
}
}

updateTooltip(): void {
super.updateTooltip();
if (!this.label) return;
this.label.title = this.tooltip;
}

label: HTMLLabelElement;
}

Expand Down
6 changes: 0 additions & 6 deletions packages/controls/src/widget_selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,6 @@ export class SelectionView extends DescriptionView {
}
}

updateTooltip(): void {
super.updateTooltip();
if (!this.listbox) return; // we might be constructing the parent
this.listbox.setAttribute('title', this.tooltip);
}

listbox: HTMLSelectElement;
}

Expand Down
12 changes: 0 additions & 12 deletions packages/controls/src/widget_string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,12 +378,6 @@ export class TextareaView extends StringView {
}
}

updateTooltip(): void {
super.updateTooltip();
if (!this.textbox) return; // we might be constructing the parent
this.textbox.setAttribute('title', this.tooltip);
}

events(): { [e: string]: string } {
return {
'keydown input': 'handleKeyDown',
Expand Down Expand Up @@ -500,12 +494,6 @@ export class TextView extends StringView {
}
}

updateTooltip(): void {
super.updateTooltip();
if (!this.textbox) return; // we might be constructing the parent
this.textbox.setAttribute('title', this.tooltip);
}

update(options?: any): void {
/**
* Update the contents of this view
Expand Down

0 comments on commit 7fa9cba

Please sign in to comment.