@@ -51,6 +51,7 @@ export interface DSelectProps<V extends DId, T extends DSelectItem<V>> extends O
5151 dClearable ?: boolean ;
5252 dDisabled ?: boolean ;
5353 dMultiple ?: boolean ;
54+ dMonospaced ?: boolean ;
5455 dVirtual ?: boolean ;
5556 dCustomItem ?: ( item : T ) => React . ReactNode ;
5657 dCustomSelected ?: ( select : T ) => string ;
@@ -89,6 +90,7 @@ function Select<V extends DId, T extends DSelectItem<V>>(
8990 dClearable = false ,
9091 dDisabled = false ,
9192 dMultiple = false ,
93+ dMonospaced = true ,
9294 dVirtual = false ,
9395 dCustomItem,
9496 dCustomSelected,
@@ -306,22 +308,45 @@ function Select<V extends DId, T extends DSelectItem<V>>(
306308 const [ transformOrigin , setTransformOrigin ] = useState < string > ( ) ;
307309 const updatePosition = useEventCallback ( ( ) => {
308310 if ( visible && boxRef . current && popupRef . current ) {
309- const width = Math . min ( boxRef . current . offsetWidth , window . innerWidth - WINDOW_SPACE * 2 ) ;
310- const height = popupRef . current . offsetHeight ;
311- const { top, left, transformOrigin } = getVerticalSidePosition (
312- boxRef . current ,
313- { width, height } ,
314- {
315- placement : 'bottom' ,
316- inWindow : WINDOW_SPACE ,
317- }
318- ) ;
319- setPopupPositionStyle ( {
320- top,
321- left,
322- width,
323- } ) ;
324- setTransformOrigin ( transformOrigin ) ;
311+ if ( dMonospaced ) {
312+ const width = Math . min ( boxRef . current . offsetWidth , window . innerWidth - WINDOW_SPACE * 2 ) ;
313+ const height = popupRef . current . offsetHeight ;
314+ const { top, left, transformOrigin } = getVerticalSidePosition (
315+ boxRef . current ,
316+ { width, height } ,
317+ {
318+ placement : 'bottom' ,
319+ inWindow : WINDOW_SPACE ,
320+ }
321+ ) ;
322+ setPopupPositionStyle ( {
323+ top,
324+ left,
325+ width,
326+ } ) ;
327+ setTransformOrigin ( transformOrigin ) ;
328+ } else {
329+ const boxWidth = boxRef . current . offsetWidth ;
330+ const height = popupRef . current . offsetHeight ;
331+ const maxWidth = window . innerWidth - WINDOW_SPACE * 2 ;
332+ const width = Math . min ( Math . max ( popupRef . current . scrollWidth , boxWidth ) , maxWidth ) ;
333+ const { top, left, transformOrigin } = getVerticalSidePosition (
334+ boxRef . current ,
335+ { width, height } ,
336+ {
337+ placement : 'bottom-left' ,
338+ inWindow : WINDOW_SPACE ,
339+ }
340+ ) ;
341+
342+ setPopupPositionStyle ( {
343+ top,
344+ left,
345+ minWidth : Math . min ( boxWidth , maxWidth ) ,
346+ maxWidth,
347+ } ) ;
348+ setTransformOrigin ( transformOrigin ) ;
349+ }
325350 }
326351 } ) ;
327352
0 commit comments