mirror of
https://github.com/twbs/bootstrap.git
synced 2025-04-06 23:57:36 +02:00
Don't add empty content holder when there is no content available (#33982)
* Remove content holder when there is no content * Add tests to check the removal of header/content Co-authored-by: XhmikosR <xhmikosr@gmail.com>
This commit is contained in:
parent
0b2d20b975
commit
153cf3a235
@ -30,7 +30,7 @@ const Default = {
|
|||||||
content: '',
|
content: '',
|
||||||
template: '<div class="popover" role="tooltip">' +
|
template: '<div class="popover" role="tooltip">' +
|
||||||
'<div class="popover-arrow"></div>' +
|
'<div class="popover-arrow"></div>' +
|
||||||
'<h3 class="popover-header"></h3>' +
|
'<h3 class="popover-header"></h3>' +
|
||||||
'<div class="popover-body"></div>' +
|
'<div class="popover-body"></div>' +
|
||||||
'</div>'
|
'</div>'
|
||||||
}
|
}
|
||||||
@ -90,6 +90,24 @@ class Popover extends Tooltip {
|
|||||||
return this.getTitle() || this._getContent()
|
return this.getTitle() || this._getContent()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getTipElement() {
|
||||||
|
if (this.tip) {
|
||||||
|
return this.tip
|
||||||
|
}
|
||||||
|
|
||||||
|
this.tip = super.getTipElement()
|
||||||
|
|
||||||
|
if (!this.getTitle()) {
|
||||||
|
this.tip.removeChild(SelectorEngine.findOne(SELECTOR_TITLE, this.tip))
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this._getContent()) {
|
||||||
|
this.tip.removeChild(SelectorEngine.findOne(SELECTOR_CONTENT, this.tip))
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.tip
|
||||||
|
}
|
||||||
|
|
||||||
setContent() {
|
setContent() {
|
||||||
const tip = this.getTipElement()
|
const tip = this.getTipElement()
|
||||||
|
|
||||||
|
@ -117,6 +117,46 @@ describe('Popover', () => {
|
|||||||
popover.show()
|
popover.show()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should show a popover with just content without having header', done => {
|
||||||
|
fixtureEl.innerHTML = '<a href="#">Nice link</a>'
|
||||||
|
|
||||||
|
const popoverEl = fixtureEl.querySelector('a')
|
||||||
|
const popover = new Popover(popoverEl, {
|
||||||
|
content: 'Some beautiful content :)'
|
||||||
|
})
|
||||||
|
|
||||||
|
popoverEl.addEventListener('shown.bs.popover', () => {
|
||||||
|
const popoverDisplayed = document.querySelector('.popover')
|
||||||
|
|
||||||
|
expect(popoverDisplayed).not.toBeNull()
|
||||||
|
expect(popoverDisplayed.querySelector('.popover-header')).toBeNull()
|
||||||
|
expect(popoverDisplayed.querySelector('.popover-body').textContent).toEqual('Some beautiful content :)')
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
|
||||||
|
popover.show()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should show a popover with just title without having body', done => {
|
||||||
|
fixtureEl.innerHTML = '<a href="#">Nice link</a>'
|
||||||
|
|
||||||
|
const popoverEl = fixtureEl.querySelector('a')
|
||||||
|
const popover = new Popover(popoverEl, {
|
||||||
|
title: 'Title, which does not require content'
|
||||||
|
})
|
||||||
|
|
||||||
|
popoverEl.addEventListener('shown.bs.popover', () => {
|
||||||
|
const popoverDisplayed = document.querySelector('.popover')
|
||||||
|
|
||||||
|
expect(popoverDisplayed).not.toBeNull()
|
||||||
|
expect(popoverDisplayed.querySelector('.popover-body')).toBeNull()
|
||||||
|
expect(popoverDisplayed.querySelector('.popover-header').textContent).toEqual('Title, which does not require content')
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
|
||||||
|
popover.show()
|
||||||
|
})
|
||||||
|
|
||||||
it('should show a popover with provided custom class', done => {
|
it('should show a popover with provided custom class', done => {
|
||||||
fixtureEl.innerHTML = '<a href="#" title="Popover" data-bs-content="https://twitter.com/getbootstrap" data-bs-custom-class="custom-class">BS twitter</a>'
|
fixtureEl.innerHTML = '<a href="#" title="Popover" data-bs-content="https://twitter.com/getbootstrap" data-bs-custom-class="custom-class">BS twitter</a>'
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user