Skip to content

Commit ec3313d

Browse files
committed
feat: autoHide function prop
1 parent 2c9c49b commit ec3313d

File tree

1 file changed

+13
-3
lines changed
  • packages/floating-vue/src/components

1 file changed

+13
-3
lines changed

packages/floating-vue/src/components/Popper.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ export default () => defineComponent({
172172
},
173173

174174
autoHide: {
175-
type: Boolean,
175+
type: [Boolean, Function],
176176
default: defaultPropFactory('autoHide'),
177177
},
178178

@@ -300,6 +300,7 @@ export default () => defineComponent({
300300
transformOrigin: null,
301301
},
302302
shownChildren: new Set(),
303+
lastAutoHide: true,
303304
}
304305
},
305306

@@ -318,7 +319,7 @@ export default () => defineComponent({
318319
isShown: this.isShown,
319320
shouldMountContent: this.shouldMountContent,
320321
skipTransition: this.skipTransition,
321-
autoHide: this.autoHide,
322+
autoHide: typeof this.autoHide === 'function' ? this.lastAutoHide : this.autoHide,
322323
show: this.show,
323324
hide: this.hide,
324325
handleResize: this.handleResize,
@@ -1119,7 +1120,16 @@ function isContainingEventTarget (popper, event): boolean {
11191120
}
11201121

11211122
function shouldAutoHide (popper, contains, event): boolean {
1122-
return event.closeAllPopover || (event.closePopover && contains) || (popper.autoHide && !contains)
1123+
return event.closeAllPopover || (event.closePopover && contains) || (getAutoHideResult(popper, event) && !contains)
1124+
}
1125+
1126+
function getAutoHideResult (popper, event) {
1127+
if (typeof popper.autoHide === 'function') {
1128+
const result = popper.autoHide(event)
1129+
popper.lastAutoHide = result
1130+
return result
1131+
}
1132+
return popper.autoHide
11231133
}
11241134

11251135
function computePositionAllShownPoppers (event) {

0 commit comments

Comments
 (0)