Demo:搜索框聚焦时禁止节点响应按键事件自动进入文本编辑状态

This commit is contained in:
街角小林 2024-08-16 09:16:07 +08:00
parent 0f305b9876
commit 8366357204

View File

@ -1,9 +1,5 @@
<template>
<div
class="searchContainer"
:class="{ isDark: isDark, show: show }"
@mouseleave="onMouseleave"
>
<div class="searchContainer" :class="{ isDark: isDark, show: show }">
<div class="closeBtnBox">
<span class="closeBtn el-icon-close" @click="close"></span>
</div>
@ -15,6 +11,8 @@
v-model="searchText"
@keyup.native.enter.stop="onSearchNext"
@keydown.native.stop
@focus="onFocus"
@blur="onBlur"
>
<i slot="prefix" class="el-input__icon el-icon-search"></i>
<el-button
@ -37,6 +35,8 @@
v-model="replaceText"
style="margin: 12px 0;"
@keydown.native.stop
@focus="onFocus"
@blur="onBlur"
>
<i slot="prefix" class="el-input__icon el-icon-edit"></i>
<el-button size="small" slot="append" @click="hideReplaceInput">{{
@ -95,11 +95,17 @@ export default {
created() {
this.$bus.$on('show_search', this.showSearch)
this.mindMap.on('search_info_change', this.handleSearchInfoChange)
this.mindMap.on('node_click', this.blur)
this.mindMap.on('draw_click', this.blur)
this.mindMap.on('expand_btn_click', this.blur)
this.mindMap.keyCommand.addShortcut('Control+f', this.showSearch)
},
beforeDestroy() {
this.$bus.$off('show_search', this.showSearch)
this.mindMap.off('search_info_change', this.handleSearchInfoChange)
this.mindMap.off('node_click', this.blur)
this.mindMap.off('draw_click', this.blur)
this.mindMap.off('expand_btn_click', this.blur)
this.mindMap.keyCommand.removeShortcut('Control+f', this.showSearch)
},
methods: {
@ -122,6 +128,30 @@ export default {
this.replaceText = ''
},
//
onFocus() {
this.mindMap.updateConfig({
enableAutoEnterTextEditWhenKeydown: false
})
},
//
onBlur() {
this.mindMap.updateConfig({
enableAutoEnterTextEditWhenKeydown: true
})
},
//
blur() {
if (this.$refs.searchInputRef) {
this.$refs.searchInputRef.blur()
}
if (this.$refs.replaceInputRef) {
this.$refs.replaceInputRef.blur()
}
},
onSearchNext() {
this.mindMap.search.search(this.searchText, () => {
this.$refs.searchInputRef.focus()
@ -144,15 +174,6 @@ export default {
this.searchText = ''
this.hideReplaceInput()
this.mindMap.search.endSearch()
},
onMouseleave() {
if (this.$refs.searchInputRef) {
this.$refs.searchInputRef.blur()
}
if (this.$refs.replaceInputRef) {
this.$refs.replaceInputRef.blur()
}
}
}
}