🌐 AI搜索 & 代理 主页
Skip to content

Commit f135cf0

Browse files
authored
Update dropdown.js
1 parent 7e676fd commit f135cf0

File tree

1 file changed

+12
-41
lines changed

1 file changed

+12
-41
lines changed

src/mixins/dropdown.js

Lines changed: 12 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import warn from '../utils/warn'
44
import { BvEvent } from '../utils/bv-event.class'
55
import { closest, contains, isVisible, requestAF, selectAll, eventOn, eventOff } from '../utils/dom'
66
import { isNull } from '../utils/inspect'
7-
import clickOutMixin from './click-out'
8-
import focusInMixin from './focus-in'
7+
import idMixin from './id'
98

109
// Return an array of visible items
1110
const filterVisibles = els => (els || []).filter(isVisible)
@@ -45,7 +44,7 @@ const AttachmentMap = {
4544

4645
// @vue/component
4746
export default {
48-
mixins: [clickOutMixin, focusInMixin],
47+
mixins: [idMixin],
4948
provide() {
5049
return {
5150
bvDropdown: this
@@ -194,9 +193,6 @@ export default {
194193
/* istanbul ignore next */
195194
return
196195
}
197-
// Ensure other menus are closed
198-
this.$root.$emit(ROOT_DROPDOWN_SHOWN, this)
199-
200196
// Are we in a navbar ?
201197
if (isNull(this.inNavbar) && this.isNav) {
202198
// We should use an injection for this
@@ -219,6 +215,9 @@ export default {
219215
}
220216
}
221217

218+
// Ensure other menus are closed
219+
this.$root.$emit(ROOT_DROPDOWN_SHOWN, this)
220+
222221
this.whileOpenListen(true)
223222

224223
// Wrap in nextTick to ensure menu is fully rendered/shown
@@ -275,16 +274,10 @@ export default {
275274
// If another dropdown is opened
276275
this.$root.$on(ROOT_DROPDOWN_SHOWN, this.rootCloseListener)
277276
// Hide the menu when focus moves out
278-
eventOn(this.$el, 'focusout', this.focusOutHandler, { passive: true })
279-
// Hide the dropdown when clicked outside
280-
// this.listenForClickOut = true
281-
// Hide the dropdown when it loses focus
282-
// this.listenForFocusIn = true
277+
eventOn(this.$el, 'focusout', this.onFocusOut, { passive: true })
283278
} else {
284279
this.$root.$off(ROOT_DROPDOWN_SHOWN, this.rootCloseListener)
285-
eventOff(this.$el, 'focusout', this.focusOutHandler, { passive: true })
286-
this.listenForClickOut = false
287-
this.listenForFocusIn = false
280+
eventOff(this.$el, 'focusout', this.onFocusOut, { passive: true })
288281
}
289282
},
290283
rootCloseListener(vm) {
@@ -318,8 +311,6 @@ export default {
318311
// Called only by a button that toggles the menu
319312
toggle(evt) {
320313
evt = evt || {}
321-
// DEBUG
322-
console.log('Toggle hanlder', evt)
323314
const type = evt.type
324315
const key = evt.keyCode
325316
if (
@@ -381,36 +372,16 @@ export default {
381372
}
382373
},
383374
// Drodpwon wrapper focusOut handler
384-
focusOutHandler(evt) {
375+
onFocusOut(evt) {
385376
// `relatedTarget` is the element gaining focus
386377
const relatedTarget = evt.relatedTarget
387-
if (this.visible && !contains(this.$refs.menu, relatedTarget)) {
388-
// DEBUG
389-
console.log('Focusout left menu', relatedTarget, evt)
390-
// If focus moves outside the menu or toggler, then close menu
378+
// If focus moves outside the menu or toggler, then close menu
379+
requestAF(() => {
391380
requestAF(() => {
392-
this.$nextTick(() => {
381+
if (this.visible && !contains(this.$refs.menu, relatedTarget)) {
393382
this.visible = false
394-
})
383+
}
395384
})
396-
}
397-
},
398-
// Document click out listener
399-
clickOutHandler() {
400-
requestAF(() => {
401-
if (this.visible) {
402-
this.visible = false
403-
}
404-
})
405-
},
406-
// Document focusin listener
407-
focusInHandler(evt) {
408-
const target = evt.target
409-
// If focus leaves dropdown, hide it
410-
requestAF(() => {
411-
if (this.visible && !contains(this.$refs.menu, target) && !contains(this.toggler, target)) {
412-
this.visible = false
413-
}
414385
})
415386
},
416387
// Keyboard nav

0 commit comments

Comments
 (0)