Skip to content

Commit

Permalink
[Popover] Popovers whose both title and content are zero-length are n…
Browse files Browse the repository at this point in the history
…ever displayed.
  • Loading branch information
wxsms committed Nov 6, 2017
1 parent ac19b34 commit 2522221
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 25 deletions.
5 changes: 1 addition & 4 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
### Browser and uiv version
### Version & browser


### Which component
Expand All @@ -11,6 +11,3 @@


### Actual behavior



8 changes: 5 additions & 3 deletions docs/pages/components/Popover.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
## Example

**Note**: Popovers whose both title and content are zero-length are never displayed.

Click the button below to toggle popover:

```html
<button type="button" class="btn btn-primary" id="popover-trigger">Popover</button>
<popover title="Title" target="#popover-trigger">
<button type="button" class="btn btn-primary" id="btn">Popover</button>
<popover title="Title" target="#btn">
<div slot="popover">
<h1>Hello world!</h1>
</div>
Expand Down Expand Up @@ -123,7 +125,7 @@ Set `enable` prop to `false` to disable a popover.

```html
<popover title="Title" :enable="false">
<button type="button" class="btn btn-primary" id="disabled-trigger">Disabled Popover</button>
<button type="button" class="btn btn-primary">Disabled Popover</button>
<div slot="popover">
<h1>Hello world!</h1>
</div>
Expand Down
31 changes: 15 additions & 16 deletions src/components/popover/Popover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -169,23 +169,22 @@
utils.off(window, utils.events.CLICK, this.windowClicked)
},
show () {
let popover = this.$refs.popover
if (!this.enable || !this.triggerEl || this.isShown()) {
return
}
if (this.timeoutId > 0) {
clearTimeout(this.timeoutId)
this.timeoutId = 0
} else {
popover.className = `${BASE_CLASS} ${this.placement}`
let container = document.querySelector(this.appendTo)
container.appendChild(popover)
utils.setTooltipPosition(popover, this.triggerEl, this.placement, this.autoPlacement, this.appendTo)
popover.offsetHeight
if (this.enable && this.triggerEl && (this.title || this.content || this.$slots.popover) && !this.isShown()) {
let popover = this.$refs.popover
if (this.timeoutId > 0) {
clearTimeout(this.timeoutId)
this.timeoutId = 0
} else {
popover.className = `${BASE_CLASS} ${this.placement}`
let container = document.querySelector(this.appendTo)
container.appendChild(popover)
utils.setTooltipPosition(popover, this.triggerEl, this.placement, this.autoPlacement, this.appendTo)
popover.offsetHeight
}
utils.addClass(popover, SHOW_CLASS)
this.$emit('input', true)
this.$emit('show')
}
utils.addClass(popover, SHOW_CLASS)
this.$emit('input', true)
this.$emit('show')
},
hide () {
if (this.isShown()) {
Expand Down
23 changes: 21 additions & 2 deletions test/unit/specs/Popover.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('Popover', () => {
})

it('should be able to show popover on init', async () => {
let res = Vue.compile('<popover v-model="show"><button data-role="trigger"></button></popover>')
let res = Vue.compile('<popover v-model="show" title="123"><button data-role="trigger"></button></popover>')
let vm = new Vue({
data () {
return {
Expand All @@ -49,8 +49,27 @@ describe('Popover', () => {
vm.$destroy()
})

it('should not show popover with no title and content', async () => {
let res = Vue.compile('<popover v-model="show"><button data-role="trigger"></button></popover>')
let vm = new Vue({
data () {
return {
show: true
}
},
components: {Popover},
render: res.render,
staticRenderFns: res.staticRenderFns
}).$mount()
await utils.sleep(200)
expect(document.querySelectorAll('.popover').length).to.equal(0)
$(vm.$el).remove()
$('.popover').remove()
vm.$destroy()
})

it('should be able to use custom target', async () => {
let res = Vue.compile('<div><button ref="btn" type="button">btn</button><popover :target="btn" trigger="focus"></popover></div>')
let res = Vue.compile('<div><button ref="btn" type="button">btn</button><popover :target="btn" trigger="focus" title="123"></popover></div>')
let vm = new Vue({
data () {
return {
Expand Down

0 comments on commit 2522221

Please sign in to comment.