mirror of https://github.com/twbs/bootstrap.git
				
				
				
			Making .tooltip('show') throw an error on elements with display:none (#20940)
This commit is contained in:
		
							parent
							
								
									0974267b8c
								
							
						
					
					
						commit
						a7f1b59959
					
				| 
						 | 
					@ -239,6 +239,9 @@ const Tooltip = (($) => {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    show() {
 | 
					    show() {
 | 
				
			||||||
 | 
					      if ($(this.element).css('display') === 'none') {
 | 
				
			||||||
 | 
					        throw new Error('Please use show on visible elements')
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
      let showEvent = $.Event(this.constructor.Event.SHOW)
 | 
					      let showEvent = $.Event(this.constructor.Event.SHOW)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if (this.isWithContent() && this._isEnabled) {
 | 
					      if (this.isWithContent() && this._isEnabled) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -320,4 +320,16 @@ $(function () {
 | 
				
			||||||
      .bootstrapPopover('show')
 | 
					      .bootstrapPopover('show')
 | 
				
			||||||
  })
 | 
					  })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  QUnit.test('should throw an error when show is called on hidden elements', function (assert) {
 | 
				
			||||||
 | 
					    assert.expect(1)
 | 
				
			||||||
 | 
					    var done = assert.async()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    try {
 | 
				
			||||||
 | 
					      $('<div data-toggle="popover" data-title="some title" data-content="@Johann-S" style="display: none"/>').bootstrapPopover('show')
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    catch (err) {
 | 
				
			||||||
 | 
					      assert.strictEqual(err.message, 'Please use show on visible elements')
 | 
				
			||||||
 | 
					      done()
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -185,6 +185,19 @@ $(function () {
 | 
				
			||||||
      .bootstrapTooltip('show')
 | 
					      .bootstrapTooltip('show')
 | 
				
			||||||
  })
 | 
					  })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  QUnit.test('should throw an error when show is called on hidden elements', function (assert) {
 | 
				
			||||||
 | 
					    assert.expect(1)
 | 
				
			||||||
 | 
					    var done = assert.async()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    try {
 | 
				
			||||||
 | 
					      $('<div title="tooltip title" style="display: none"/>').bootstrapTooltip('show')
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    catch (err) {
 | 
				
			||||||
 | 
					      assert.strictEqual(err.message, 'Please use show on visible elements')
 | 
				
			||||||
 | 
					      done()
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  QUnit.test('should fire inserted event', function (assert) {
 | 
					  QUnit.test('should fire inserted event', function (assert) {
 | 
				
			||||||
    assert.expect(2)
 | 
					    assert.expect(2)
 | 
				
			||||||
    var done = assert.async()
 | 
					    var done = assert.async()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue