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 @@ -1095,14 +1095,20 @@ export class DOMWidgetView extends WidgetView {
10951095 }
10961096
10971097 updateTooltip ( ) : void {
1098- const title = this . model . get ( ' tooltip' ) ;
1098+ const title = this . tooltip ;
10991099 if ( ! title ) {
11001100 this . el . removeAttribute ( 'title' ) ;
1101- } else if ( this . model . get ( 'description' ) . length === 0 ) {
1101+ } else if ( ! this . model . get ( 'description' ) ) {
11021102 this . el . setAttribute ( 'title' , title ) ;
11031103 }
11041104 }
11051105
1106+ get tooltip ( ) {
1107+ return (
1108+ this . model . get ( 'tooltip' ) ?? ( this . model . get ( 'description' ) )
1109+ ) ;
1110+ }
1111+
11061112 /**
11071113 * Update the DOM classes applied to an element, default to this.el.
11081114 */
Original file line number Diff line number Diff line change @@ -153,8 +153,7 @@ export class CheckboxView extends DescriptionView {
153153 this . descriptionSpan . textContent = description ;
154154 }
155155 this . typeset ( this . descriptionSpan ) ;
156- this . descriptionSpan . title = description ;
157- this . checkbox . title = description ;
156+ this . updateTooltip ( ) ;
158157 }
159158
160159 /**
@@ -181,13 +180,11 @@ export class CheckboxView extends DescriptionView {
181180 }
182181
183182 updateTooltip ( ) : void {
183+ super . updateTooltip ( ) ;
184184 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 ) ;
191188 }
192189
193190 events ( ) : { [ e : string ] : string } {
Original file line number Diff line number Diff line change @@ -98,8 +98,9 @@ export class DescriptionView extends DOMWidgetView {
9898 }
9999
100100 updateTooltip ( ) : void {
101+ super . updateTooltip ( ) ;
101102 if ( ! this . label ) return ;
102- this . label . title = this . model . get ( ' tooltip' ) ;
103+ this . label . title = this . tooltip ;
103104 }
104105
105106 label : HTMLLabelElement ;
Original file line number Diff line number Diff line change @@ -68,13 +68,9 @@ export class SelectionView extends DescriptionView {
6868 }
6969
7070 updateTooltip ( ) : void {
71+ super . updateTooltip ( ) ;
7172 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 ) ;
7874 }
7975
8076 listbox : HTMLSelectElement ;
Original file line number Diff line number Diff line change @@ -379,13 +379,9 @@ export class TextareaView extends StringView {
379379 }
380380
381381 updateTooltip ( ) : void {
382+ super . updateTooltip ( ) ;
382383 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 ) ;
389385 }
390386
391387 events ( ) : { [ e : string ] : string } {
@@ -505,13 +501,9 @@ export class TextView extends StringView {
505501 }
506502
507503 updateTooltip ( ) : void {
504+ super . updateTooltip ( ) ;
508505 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 ) ;
515507 }
516508
517509 update ( options ?: any ) : void {
Original file line number Diff line number Diff line change @@ -59,6 +59,7 @@ def func():
5959
6060 msg_id = Unicode ('' , help = "Parent message id of messages to capture" ).tag (sync = True )
6161 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 )
6263
6364 __counter = 0
6465
You can’t perform that action at this time.
0 commit comments