Skip to content

Commit bf3e31b

Browse files
authored
Merge pull request bootstrap-vue#114 from SirLamer/popover-refactor
Popover: Fix 'hide' event detection and convert 'debounce' to property
2 parents 3ec4a12 + 2e6a4ed commit bf3e31b

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

components/popover.vue

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ const triggerListeners = {
2727
focus: {focus: 'show', blur: 'hide'}
2828
};
2929
30-
// When using multiple event hooks, subsequent events within the defined timeframe, in milliseconds, will be ignored.
31-
// Allows for safe stacking of similar event hooks without the popover flickering.
32-
const debounceMilliseconds = 200;
33-
3430
export default {
3531
replace: true,
3632
@@ -105,6 +101,13 @@ export default {
105101
106102
return false;
107103
}
104+
},
105+
debounce: {
106+
type: [Number],
107+
default: 100,
108+
validator(value) {
109+
return value >= 0;
110+
}
108111
}
109112
},
110113
@@ -255,7 +258,7 @@ export default {
255258
*/
256259
eventHandler(e) {
257260
// If this event is right after a previous successful event, ignore it
258-
if (this.useDebounce && this.lastEvent !== null && e.timeStamp <= this.lastEvent + debounceMilliseconds) {
261+
if (this.useDebounce && this.debounce > 0 && this.lastEvent !== null && e.timeStamp <= this.lastEvent + this.debounce) {
259262
return;
260263
}
261264
@@ -267,7 +270,7 @@ export default {
267270
const action = triggerListeners[trigger][event];
268271
269272
// If the expected event action is the opposite of the current state, allow it
270-
if (action === 'toggle' || (this.showState && action === 'hide') || action === 'show') {
273+
if (action === 'toggle' || (this.showState && action === 'hide') || (!this.showState && action === 'show')) {
271274
this.showState = !this.showState;
272275
this.lastEvent = e.timeStamp;
273276
}

0 commit comments

Comments
 (0)