File tree Expand file tree Collapse file tree 6 files changed +22
-29
lines changed
python/ipywidgets/ipywidgets/widgets Expand file tree Collapse file tree 6 files changed +22
-29
lines changed Original file line number Diff line number Diff line change @@ -1096,14 +1096,20 @@ export class DOMWidgetView extends WidgetView {
1096
1096
}
1097
1097
1098
1098
updateTooltip ( ) : void {
1099
- const title = this . model . get ( ' tooltip' ) ;
1099
+ const title = this . tooltip ;
1100
1100
if ( ! title ) {
1101
1101
this . el . removeAttribute ( 'title' ) ;
1102
- } else if ( this . model . get ( 'description' ) . length === 0 ) {
1102
+ } else if ( ! this . model . get ( 'description' ) ) {
1103
1103
this . el . setAttribute ( 'title' , title ) ;
1104
1104
}
1105
1105
}
1106
1106
1107
+ get tooltip ( ) {
1108
+ return (
1109
+ this . model . get ( 'tooltip' ) ?? ( this . model . get ( 'description' ) )
1110
+ ) ;
1111
+ }
1112
+
1107
1113
/**
1108
1114
* Update the DOM classes applied to an element, default to this.el.
1109
1115
*/
Original file line number Diff line number Diff line change @@ -153,8 +153,7 @@ export class CheckboxView extends DescriptionView {
153
153
this . descriptionSpan . textContent = description ;
154
154
}
155
155
this . typeset ( this . descriptionSpan ) ;
156
- this . descriptionSpan . title = description ;
157
- this . checkbox . title = description ;
156
+ this . updateTooltip ( ) ;
158
157
}
159
158
160
159
/**
@@ -181,13 +180,11 @@ export class CheckboxView extends DescriptionView {
181
180
}
182
181
183
182
updateTooltip ( ) : void {
183
+ super . updateTooltip ( ) ;
184
184
if ( ! this . checkbox ) return ; // we might be constructing the parent
185
- const title = this . model . get ( 'tooltip' ) ;
186
- if ( ! title ) {
187
- this . checkbox . removeAttribute ( 'title' ) ;
188
- } else if ( this . model . get ( 'description' ) . length === 0 ) {
189
- this . checkbox . setAttribute ( 'title' , title ) ;
190
- }
185
+ const title = this . tooltip ;
186
+ this . checkbox . setAttribute ( 'title' , title ) ;
187
+ this . descriptionSpan . setAttribute ( 'title' , title ) ;
191
188
}
192
189
193
190
events ( ) : { [ e : string ] : string } {
Original file line number Diff line number Diff line change @@ -98,8 +98,9 @@ export class DescriptionView extends DOMWidgetView {
98
98
}
99
99
100
100
updateTooltip ( ) : void {
101
+ super . updateTooltip ( ) ;
101
102
if ( ! this . label ) return ;
102
- this . label . title = this . model . get ( ' tooltip' ) ;
103
+ this . label . title = this . tooltip ;
103
104
}
104
105
105
106
label : HTMLLabelElement ;
Original file line number Diff line number Diff line change @@ -68,13 +68,9 @@ export class SelectionView extends DescriptionView {
68
68
}
69
69
70
70
updateTooltip ( ) : void {
71
+ super . updateTooltip ( ) ;
71
72
if ( ! this . listbox ) return ; // we might be constructing the parent
72
- const title = this . model . get ( 'tooltip' ) ;
73
- if ( ! title ) {
74
- this . listbox . removeAttribute ( 'title' ) ;
75
- } else if ( this . model . get ( 'description' ) . length === 0 ) {
76
- this . listbox . setAttribute ( 'title' , title ) ;
77
- }
73
+ this . listbox . setAttribute ( 'title' , this . tooltip ) ;
78
74
}
79
75
80
76
listbox : HTMLSelectElement ;
Original file line number Diff line number Diff line change @@ -379,13 +379,9 @@ export class TextareaView extends StringView {
379
379
}
380
380
381
381
updateTooltip ( ) : void {
382
+ super . updateTooltip ( ) ;
382
383
if ( ! this . textbox ) return ; // we might be constructing the parent
383
- const title = this . model . get ( 'tooltip' ) ;
384
- if ( ! title ) {
385
- this . textbox . removeAttribute ( 'title' ) ;
386
- } else if ( this . model . get ( 'description' ) . length === 0 ) {
387
- this . textbox . setAttribute ( 'title' , title ) ;
388
- }
384
+ this . textbox . setAttribute ( 'title' , this . tooltip ) ;
389
385
}
390
386
391
387
events ( ) : { [ e : string ] : string } {
@@ -505,13 +501,9 @@ export class TextView extends StringView {
505
501
}
506
502
507
503
updateTooltip ( ) : void {
504
+ super . updateTooltip ( ) ;
508
505
if ( ! this . textbox ) return ; // we might be constructing the parent
509
- const title = this . model . get ( 'tooltip' ) ;
510
- if ( ! title ) {
511
- this . textbox . removeAttribute ( 'title' ) ;
512
- } else if ( this . model . get ( 'description' ) . length === 0 ) {
513
- this . textbox . setAttribute ( 'title' , title ) ;
514
- }
506
+ this . textbox . setAttribute ( 'title' , this . tooltip ) ;
515
507
}
516
508
517
509
update ( options ?: any ) : void {
Original file line number Diff line number Diff line change @@ -59,6 +59,7 @@ def func():
59
59
60
60
msg_id = Unicode ('' , help = "Parent message id of messages to capture" ).tag (sync = True )
61
61
outputs = TypedTuple (trait = Dict (), help = "The output messages synced from the frontend." ).tag (sync = True )
62
+ tooltip = Unicode ('' , allow_none = True , help = "A tooltip caption." ).tag (sync = True )
62
63
63
64
__counter = 0
64
65
You can’t perform that action at this time.
0 commit comments