@@ -13,80 +13,9 @@ interface IProps {
1313 noPadding : boolean ;
1414}
1515
16- interface IState {
17- availableWidth : number | null ;
18- }
19-
20- /**
21- * This component should only be used within a `MultiSelectTreeWithTemplate` component
22- */
23- export class DropdownItemTemplate extends React . PureComponent < IProps , IState > {
24- private containerRef : React . RefObject < HTMLSpanElement > ;
25-
26- constructor ( props : IProps ) {
27- super ( props ) ;
28- this . containerRef = React . createRef ( ) ;
29- this . state = {
30- availableWidth : null ,
31- } ;
32- }
33-
34- componentDidMount ( ) {
35- this . calculateAvailableWidth ( ) ;
36- }
37-
38- componentDidUpdate ( ) {
39- this . calculateAvailableWidth ( ) ;
40- }
41-
42- private calculateAvailableWidth = ( ) => {
43- const container = this . containerRef . current ;
44-
45- if ( container == null ) {
46- return ;
47- }
48-
49- // Find the tags-input__helper-box or tags-input__single-item container
50- let widthContainer : HTMLElement | null = container . parentElement ;
51-
52- while ( widthContainer != null ) {
53- if (
54- widthContainer . classList . contains ( 'tags-input__helper-box' ) ||
55- widthContainer . classList . contains ( 'tags-input__single-item' )
56- ) {
57- break ;
58- }
59-
60- widthContainer = widthContainer . parentElement ;
61- }
62-
63- if ( widthContainer == null ) {
64- return ;
65- }
66-
67- const containerWidth = widthContainer . clientWidth ;
68- const containerStyle = window . getComputedStyle ( widthContainer ) ;
69- const containerPadding = parseFloat ( containerStyle . paddingLeft ) + parseFloat ( containerStyle . paddingRight ) ;
70-
71- // Account for sibling elements (like the remove button)
72- let siblingsWidth = 0 ;
73-
74- for ( const child of Array . from ( widthContainer . children ) ) {
75- if ( ! child . contains ( container ) ) {
76- siblingsWidth += ( child as HTMLElement ) . offsetWidth ;
77- }
78- }
79-
80- const availableWidth = containerWidth - containerPadding - siblingsWidth ;
81-
82- if ( availableWidth !== this . state . availableWidth && availableWidth > 0 ) {
83- this . setState ( { availableWidth} ) ;
84- }
85- } ;
86-
16+ export class DropdownItemTemplate extends React . PureComponent < IProps > {
8717 render ( ) {
8818 const { option, noPadding, config} = this . props ;
89- const { availableWidth} = this . state ;
9019
9120 if ( option == null ) {
9221 return null ;
@@ -95,26 +24,18 @@ export class DropdownItemTemplate extends React.PureComponent<IProps, IState> {
9524 const itemStyle : React . CSSProperties = {
9625 height : '1.5em' ,
9726 minWidth : '1.5em' ,
98- maxWidth : availableWidth != null ? `${ availableWidth } px` : undefined ,
9927 backgroundColor : option . color ?? 'transparent' ,
10028 color : option . color == null ? 'black' : getTextColor ( option . color ) ,
10129 display : 'inline-flex' ,
10230 justifyContent : 'center' ,
10331 alignItems : 'center' ,
10432 borderRadius : config . source === 'manual-entry' && config . roundCorners ? '999px' : '2px' ,
10533 padding : noPadding ? '0' : '4px' ,
106- } ;
107-
108- const labelStyle : React . CSSProperties = {
10934 whiteSpace : 'nowrap' ,
110- overflow : 'hidden' ,
111- textOverflow : 'ellipsis' ,
11235 } ;
11336
11437 return (
115- < span ref = { this . containerRef } style = { itemStyle } >
116- < span style = { labelStyle } > { option . label } </ span >
117- </ span >
38+ < span style = { itemStyle } > { option . label } </ span >
11839 ) ;
11940 }
12041}
0 commit comments