@@ -29,7 +29,6 @@ import TemplateFactory from './util/template-factory'
2929const NAME = 'tooltip'
3030const DATA_KEY = 'bs.tooltip'
3131const EVENT_KEY = `.${ DATA_KEY } `
32- const CLASS_PREFIX = 'bs-tooltip'
3332const DISALLOWED_ATTRIBUTES = new Set ( [ 'sanitize' , 'allowList' , 'sanitizeFn' ] )
3433
3534const CLASS_NAME_FADE = 'fade'
@@ -232,13 +231,6 @@ class Tooltip extends BaseComponent {
232231
233232 this . _element . setAttribute ( 'aria-describedby' , tip . getAttribute ( 'id' ) )
234233
235- const placement = typeof this . _config . placement === 'function' ?
236- this . _config . placement . call ( this , tip , this . _element ) :
237- this . _config . placement
238-
239- const attachment = this . _getAttachment ( placement )
240- this . _addAttachmentClass ( attachment )
241-
242234 const { container } = this . _config
243235 Data . set ( tip , this . constructor . DATA_KEY , this )
244236
@@ -250,6 +242,10 @@ class Tooltip extends BaseComponent {
250242 if ( this . _popper ) {
251243 this . _popper . update ( )
252244 } else {
245+ const placement = typeof this . _config . placement === 'function' ?
246+ this . _config . placement . call ( this , tip , this . _element ) :
247+ this . _config . placement
248+ const attachment = AttachmentMap [ placement . toUpperCase ( ) ]
253249 this . _popper = Popper . createPopper ( this . _element , tip , this . _getPopperConfig ( attachment ) )
254250 }
255251
@@ -295,7 +291,6 @@ class Tooltip extends BaseComponent {
295291 tip . remove ( )
296292 }
297293
298- this . _cleanTipClass ( )
299294 this . _element . removeAttribute ( 'aria-describedby' )
300295 EventHandler . trigger ( this . _element , this . constructor . Event . HIDDEN )
301296
@@ -346,6 +341,8 @@ class Tooltip extends BaseComponent {
346341
347342 const tip = templateFactory . toHtml ( )
348343 tip . classList . remove ( CLASS_NAME_FADE , CLASS_NAME_SHOW )
344+ // todo on v6 the following can be done on css only
345+ tip . classList . add ( `bs-${ this . constructor . NAME } -auto` )
349346
350347 const tipId = getUID ( this . constructor . NAME ) . toString ( )
351348
@@ -463,19 +460,8 @@ class Tooltip extends BaseComponent {
463460 options : {
464461 element : SELECTOR_TOOLTIP_ARROW
465462 }
466- } ,
467- {
468- name : 'onChange' ,
469- enabled : true ,
470- phase : 'afterWrite' ,
471- fn : data => this . _handlePopperPlacementChange ( data )
472- }
473- ] ,
474- onFirstUpdate : data => {
475- if ( data . options . placement !== data . placement ) {
476- this . _handlePopperPlacementChange ( data )
477463 }
478- }
464+ ]
479465 }
480466
481467 return {
@@ -484,14 +470,6 @@ class Tooltip extends BaseComponent {
484470 }
485471 }
486472
487- _addAttachmentClass ( attachment ) {
488- this . getTipElement ( ) . classList . add ( `${ this . _getBasicClassPrefix ( ) } -${ this . updateAttachment ( attachment ) } ` )
489- }
490-
491- _getAttachment ( placement ) {
492- return AttachmentMap [ placement . toUpperCase ( ) ]
493- }
494-
495473 _setListeners ( ) {
496474 const triggers = this . _config . trigger . split ( ' ' )
497475
@@ -652,33 +630,6 @@ class Tooltip extends BaseComponent {
652630 return config
653631 }
654632
655- _cleanTipClass ( ) {
656- const tip = this . getTipElement ( )
657- const basicClassPrefixRegex = new RegExp ( `(^|\\s)${ this . _getBasicClassPrefix ( ) } \\S+` , 'g' )
658- const tabClass = tip . getAttribute ( 'class' ) . match ( basicClassPrefixRegex )
659- if ( tabClass !== null && tabClass . length > 0 ) {
660- for ( const tClass of tabClass . map ( token => token . trim ( ) ) ) {
661- tip . classList . remove ( tClass )
662- }
663- }
664- }
665-
666- _getBasicClassPrefix ( ) {
667- return CLASS_PREFIX
668- }
669-
670- _handlePopperPlacementChange ( popperData ) {
671- const { state } = popperData
672-
673- if ( ! state ) {
674- return
675- }
676-
677- this . tip = state . elements . popper
678- this . _cleanTipClass ( )
679- this . _addAttachmentClass ( this . _getAttachment ( state . placement ) )
680- }
681-
682633 _disposePopper ( ) {
683634 if ( this . _popper ) {
684635 this . _popper . destroy ( )
0 commit comments