1- import { defineComponent , ref , computed , nextTick , watch , SetupContext , getCurrentInstance } from 'vue' ;
1+ import { defineComponent , ref , computed , nextTick , watch , SetupContext , getCurrentInstance , Teleport , Transition } from 'vue' ;
22import { createI18nTranslate } from '../../locale/create' ;
3- import clickoutsideDirective from '../../shared/devui-directive/clickoutside' ;
4- import removeBtnSvg from './icon-remove' ;
3+ import ClickOutside from '../../shared/devui-directive/clickoutside' ;
4+ import { FlexibleOverlay } from '../../overlay/src/flexible-overlay' ;
5+ import removeBtnSvg from './components/icon-remove' ;
56import { Suggestion , TagInputProps , tagInputProps } from './tag-input-types' ;
67import './tag-input.scss' ;
78
@@ -16,7 +17,7 @@ const KEYS_MAP = {
1617export default defineComponent ( {
1718 name : 'DTagInput' ,
1819 directives : {
19- clickoutside : clickoutsideDirective ,
20+ ClickOutside ,
2021 } ,
2122 props : tagInputProps ,
2223 emits : [ 'update:tags' , 'update:suggestionList' , 'valueChange' ] ,
@@ -67,14 +68,11 @@ export default defineComponent({
6768 selectIndex . value > 0 ? selectIndex . value -- : ( selectIndex . value = mergedSuggestions . value . length - 1 ) ;
6869 } ;
6970
70- const tagInputRef = ref < HTMLInputElement | null > ( null ) ;
71+ const tagInputRef = ref ( ) ;
7172 const isInputBoxFocus = ref ( false ) ;
7273 const onInputFocus = ( ) => {
7374 isInputBoxFocus . value = true ;
7475 } ;
75- const onInputBlur = ( ) => {
76- // isInputBoxFocus.value = false;
77- } ;
7876
7977 // 点击元素外部区域关闭Suggestion选择
8078 const closeSuggestion = ( ) => {
@@ -173,7 +171,9 @@ export default defineComponent({
173171
174172 const noDataTpl = < li class = "devui-suggestion-item devui-disabled" > { props . noData } </ li > ;
175173
176- return ( ) => ( < div class = "devui-tags-host" tabIndex = "-1" v-clickoutside = { closeSuggestion } >
174+ const origin = ref ( ) ;
175+
176+ return ( ) => ( < div class = "devui-tags-host" ref = { origin } v-click-outside = { closeSuggestion } >
177177 < div class = { inputBoxCls } style = { [ 'box-shadow: none;' ] } >
178178 < ul class = "devui-tag-list" title = { props . disabled ? props . disabledText : '' } >
179179 { props . tags . map ( ( tag , tagIdx ) => {
@@ -197,33 +197,42 @@ export default defineComponent({
197197 style = { tagInputStyle }
198198 onKeyDown = { onInputKeydown }
199199 onFocus = { onInputFocus }
200- onBlur = { onInputBlur }
201200 onInput = { ( $event : InputEvent ) => onInput ( $event ) }
202201 placeholder = { isTagsLimit . value ? `${ props . maxTagsText || t ( 'maxTagsText' ) } ${ props . maxTags } ` : props . placeholder }
203202 spellCheck = { props . spellcheck }
204203 disabled = { isTagsLimit . value }
205204 />
206205 </ div >
207- { isShowSuggestion . value && (
208- < div class = "devui-tags-autocomplete devui-dropdown-menu" >
209- < ul class = "devui-suggestion-list" >
210- { mergedSuggestions . value . length === 0
211- ? noDataTpl
212- : mergedSuggestions . value . map ( ( item : Suggestion , index : number ) => {
213- return (
214- < li
215- class = { { 'devui-suggestion-item' : true , selected : index === selectIndex . value } }
216- onClick = { ( $event : Event ) => {
217- onSuggestionItemClick ( $event , index ) ;
218- } }
219- >
220- { item [ props . displayProperty ] }
221- </ li >
222- ) ;
223- } ) }
224- </ ul >
225- </ div >
226- ) }
206+
207+ < Teleport to = "body" >
208+ < Transition name = "fade" >
209+ < FlexibleOverlay
210+ origin = { origin . value }
211+ v-model = { isShowSuggestion . value }
212+ style = { { zIndex : 'var(--devui-z-index-dropdown, 1052)' , width : '100%' } }
213+ >
214+ < div class = "devui-tags-autocomplete devui-dropdown-menu" style = { { width : '100%' } } >
215+ < ul class = "devui-suggestion-list" >
216+ { mergedSuggestions . value . length === 0
217+ ? noDataTpl
218+ : mergedSuggestions . value . map ( ( item : Suggestion , index : number ) => {
219+ return (
220+ < li
221+ class = { { 'devui-suggestion-item' : true , selected : index === selectIndex . value } }
222+ onClick = { ( $event : Event ) => {
223+ $event . stopPropagation ( ) ;
224+ onSuggestionItemClick ( $event , index ) ;
225+ } }
226+ >
227+ { item [ props . displayProperty ] }
228+ </ li >
229+ ) ;
230+ } ) }
231+ </ ul >
232+ </ div >
233+ </ FlexibleOverlay >
234+ </ Transition >
235+ </ Teleport >
227236 </ div > ) ;
228237 } ,
229238} ) ;
0 commit comments