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

Add tooltip attribute to description widgets #1864 #2070

Merged
merged 5 commits into from
Jul 6, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions ipywidgets/widgets/widget_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class DescriptionWidget(DOMWidget, CoreWidget):
"""Widget that has a description label to the side."""
_model_name = Unicode('DescriptionModel').tag(sync=True)
description = Unicode('', help="Description of the control.").tag(sync=True)
tooltip = Unicode('', help="Tooltip for the description.").tag(sync=True)
style = InstanceDict(DescriptionStyle, help="Styling customizations").tag(sync=True, **widget_serialization)

def _repr_keys(self):
Expand Down
9 changes: 8 additions & 1 deletion packages/controls/src/widget_description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class DescriptionModel extends DOMWidgetModel {
_view_module_version: JUPYTER_CONTROLS_VERSION,
_model_module_version: JUPYTER_CONTROLS_VERSION,
description: '',
tooltip: '',
};
}
}
Expand All @@ -56,6 +57,7 @@ class DescriptionView extends DOMWidgetView {
this.label.style.display = 'none';

this.listenTo(this.model, 'change:description', this.updateDescription);
this.listenTo(this.model, 'change:tooltip', this.updateDescription);
this.updateDescription();
}

Expand All @@ -65,14 +67,19 @@ class DescriptionView extends DOMWidgetView {

updateDescription() {
let description = this.model.get('description');
let tooltip = this.model.get('tooltip');
if (tooltip.length === 0) {
tooltip = description;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would we disable the tooltip if we didn't want it to show up?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I understand, it couldn't be disabled completely previously also since it always defaults to the description. Not specifying the tooltip or setting it to an empty string will result in closest behavior.

}

if (description.length === 0) {
this.label.style.display = 'none';
} else {
this.label.innerHTML = description;
this.typeset(this.label);
this.label.style.display = '';
}
this.label.title = description;
this.label.title = tooltip;
}

label: HTMLLabelElement;
Expand Down