Skip to content

Commit

Permalink
feat: autoHide function prop
Browse files Browse the repository at this point in the history
  • Loading branch information
Akryum committed Apr 11, 2022
1 parent 2c9c49b commit ec3313d
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions packages/floating-vue/src/components/Popper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export default () => defineComponent({
},

autoHide: {
type: Boolean,
type: [Boolean, Function],
default: defaultPropFactory('autoHide'),
},

Expand Down Expand Up @@ -300,6 +300,7 @@ export default () => defineComponent({
transformOrigin: null,
},
shownChildren: new Set(),
lastAutoHide: true,
}
},

Expand All @@ -318,7 +319,7 @@ export default () => defineComponent({
isShown: this.isShown,
shouldMountContent: this.shouldMountContent,
skipTransition: this.skipTransition,
autoHide: this.autoHide,
autoHide: typeof this.autoHide === 'function' ? this.lastAutoHide : this.autoHide,
show: this.show,
hide: this.hide,
handleResize: this.handleResize,
Expand Down Expand Up @@ -1119,7 +1120,16 @@ function isContainingEventTarget (popper, event): boolean {
}

function shouldAutoHide (popper, contains, event): boolean {
return event.closeAllPopover || (event.closePopover && contains) || (popper.autoHide && !contains)
return event.closeAllPopover || (event.closePopover && contains) || (getAutoHideResult(popper, event) && !contains)
}

function getAutoHideResult (popper, event) {
if (typeof popper.autoHide === 'function') {
const result = popper.autoHide(event)
popper.lastAutoHide = result
return result
}
return popper.autoHide
}

function computePositionAllShownPoppers (event) {
Expand Down

0 comments on commit ec3313d

Please sign in to comment.