@@ -12,6 +12,7 @@ import React, { useCallback, useState, useId, useMemo, useRef } from 'react';
1212import { useEventNotify } from '@react-devui/hooks' ;
1313import { CloseOutlined , LoadingOutlined } from '@react-devui/icons' ;
1414import { findNested , getClassName , getOriginalSize , getVerticalSidePosition } from '@react-devui/utils' ;
15+ import { POSITION_CONFIG } from '@react-devui/utils/position/config' ;
1516
1617import { usePrefixConfig , useComponentConfig , useGeneralContext , useDValue , useTranslation } from '../../hooks' ;
1718import { registerComponentMate } from '../../utils' ;
@@ -288,26 +289,6 @@ function TreeSelect<V extends DId, T extends DTreeItem<V> & { children?: T[] }>(
288289 }
289290 } ;
290291
291- const updatePosition = useCallback (
292- ( boxEl : HTMLElement , popupEl : HTMLElement ) => {
293- const width = boxEl . getBoundingClientRect ( ) . width ;
294- const { height } = getOriginalSize ( popupEl ) ;
295- const { top, left, transformOrigin } = getVerticalSidePosition ( boxEl , { width, height } , 'bottom-left' , 8 ) ;
296-
297- return {
298- position : {
299- top,
300- left,
301- width : hasSearch ? width : undefined ,
302- minWidth : hasSearch ? undefined : width ,
303- maxWidth : window . innerWidth - left - 20 ,
304- } ,
305- transformOrigin,
306- } ;
307- } ,
308- [ hasSearch ]
309- ) ;
310-
311292 const [ selectedNode , suffixNode , selectedLabel ] = ( ( ) => {
312293 let selectedNode : React . ReactNode = null ;
313294 let suffixNode : React . ReactNode = null ;
@@ -427,7 +408,26 @@ function TreeSelect<V extends DId, T extends DTreeItem<V> & { children?: T[] }>(
427408 } ,
428409 } }
429410 dInputRef = { dInputRef }
430- dUpdatePosition = { updatePosition }
411+ dUpdatePosition = { ( boxEl , popupEl ) => {
412+ const boxWidth = boxEl . getBoundingClientRect ( ) . width ;
413+ const minWidth = Math . min ( boxWidth , window . innerWidth - POSITION_CONFIG . space * 2 ) ;
414+ const { width, height } = getOriginalSize ( popupEl ) ;
415+ const { top, left, transformOrigin } = getVerticalSidePosition (
416+ boxEl ,
417+ { width : Math . max ( width , minWidth ) , height } ,
418+ 'bottom-left' ,
419+ 8
420+ ) ;
421+
422+ return {
423+ position : {
424+ top,
425+ left,
426+ minWidth,
427+ } ,
428+ transformOrigin,
429+ } ;
430+ } }
431431 afterVisibleChange = { afterVisibleChange }
432432 onFocusVisibleChange = { setFocusVisible }
433433 onClear = { handleClear }
0 commit comments