@@ -24,9 +24,7 @@ const metadata = {
24
24
properties : /** @lends sap.ui.webcomponents.main.Tokenizer.prototype */ {
25
25
showMore : { type : Boolean } ,
26
26
disabled : { type : Boolean } ,
27
-
28
- _nMoreText : { type : String , noAttribute : true } ,
29
- _hiddenTokens : { type : Object , multiple : true } ,
27
+ _nMoreText : { type : String } ,
30
28
} ,
31
29
events : /** @lends sap.ui.webcomponents.main.Tokenizer.prototype */ {
32
30
tokenDelete : {
@@ -75,13 +73,18 @@ class Tokenizer extends UI5Element {
75
73
return styles ;
76
74
}
77
75
76
+ _handleResize ( ) {
77
+ /*
78
+ * Overflow happens with a pure CSS, but we
79
+ * have to update the "n more" label when tokenizer is resized
80
+ */
81
+ this . _invalidate ( ) ;
82
+ }
83
+
78
84
constructor ( ) {
79
85
super ( ) ;
80
86
81
- this . _itemsCount = 0 ;
82
- this . _lastIndex = 0 ;
83
- this . _lastTokenCount = 0 ;
84
- this . _recalculateLayouting = false ;
87
+ this . _tokensCount = 0 ;
85
88
this . _resizeHandler = this . _handleResize . bind ( this ) ;
86
89
this . _itemNav = new ItemNavigation ( this ) ;
87
90
@@ -101,20 +104,12 @@ class Tokenizer extends UI5Element {
101
104
onBeforeRendering ( ) {
102
105
this . _itemNav . init ( ) ;
103
106
104
- if ( this . _lastTokenCount !== this . tokens . length ) {
105
- this . _recalculateLayouting = true ;
106
- }
107
-
108
- this . _lastTokenCount = this . tokens . length ;
109
- this . _nMoreText = this . resourceBundle . getText ( MULTIINPUT_SHOW_MORE_TOKENS , [ this . _hiddenTokens . length ] ) ;
107
+ setTimeout ( ( ) => {
108
+ // wait for the layouting and update the text
109
+ this . _nMoreText = this . resourceBundle . getText ( MULTIINPUT_SHOW_MORE_TOKENS , [ this . overflownTokensCount ] ) ;
110
+ } , 0 ) ;
110
111
}
111
112
112
- onAfterRendering ( ) {
113
- if ( this . _recalculateLayouting ) {
114
- this . _handleResize ( ) ;
115
- this . _recalculateLayouting = false ;
116
- }
117
- }
118
113
119
114
onEnterDOM ( ) {
120
115
ResizeHandler . register ( this . shadowRoot . querySelector ( ".ui5-tokenizer--content" ) , this . _resizeHandler ) ;
@@ -128,37 +123,19 @@ class Tokenizer extends UI5Element {
128
123
this . fireEvent ( "showMoreItemsPress" ) ;
129
124
}
130
125
131
- _handleResize ( ) {
132
- const overflowTokens = this . _getTokens ( true ) ;
133
-
134
- if ( ! overflowTokens . length ) {
135
- this . _hiddenTokens = [ ] ;
136
- }
137
-
138
- this . _hiddenTokens = overflowTokens ;
126
+ _getTokens ( ) {
127
+ return this . tokens ;
139
128
}
140
129
141
- _getTokens ( overflow ) {
142
- const firstToken = this . shadowRoot . querySelector ( ".ui5-tokenizer-token-placeholder" ) ;
143
-
144
- if ( ! firstToken ) {
145
- return [ ] ;
146
- }
147
-
148
- const firstTokenTop = firstToken . getBoundingClientRect ( ) . top ;
149
- const tokens = [ ] ;
150
-
151
- if ( firstToken && this . tokens . length ) {
152
- this . tokens . forEach ( token => {
153
- const tokenTop = token . getBoundingClientRect ( ) . top ;
154
- const tokenOverflows = overflow && tokenTop > firstTokenTop ;
155
- const tokenVisible = ! overflow && tokenTop <= firstTokenTop ;
156
-
157
- ( tokenVisible || tokenOverflows ) && tokens . push ( token ) ;
158
- } ) ;
130
+ onAfterRendering ( ) {
131
+ /*
132
+ We schedule an invalidation as we have the tokens count
133
+ changed and we need them rendered for the nmore count
134
+ */
135
+ if ( this . _tokensCount !== this . tokens . length ) {
136
+ this . _invalidate ( ) ;
137
+ this . _tokensCount = this . tokens . length ;
159
138
}
160
-
161
- return tokens ;
162
139
}
163
140
164
141
_tokenDelete ( event ) {
@@ -193,7 +170,22 @@ class Tokenizer extends UI5Element {
193
170
}
194
171
195
172
get showNMore ( ) {
196
- return this . showMore && this . _hiddenTokens . length ;
173
+ return this . showMore && this . overflownTokensCount ;
174
+ }
175
+
176
+ get overflownTokensCount ( ) {
177
+ const placeholderToken = this . shadowRoot . querySelector ( ".ui5-tokenizer-token-placeholder" ) ;
178
+
179
+ if ( ! placeholderToken ) {
180
+ return ;
181
+ }
182
+
183
+ const placeholderTokenRect = placeholderToken . getBoundingClientRect ( ) ;
184
+ const tokens = this . tokens . filter ( token => {
185
+ return placeholderTokenRect . top < token . getBoundingClientRect ( ) . top ;
186
+ } ) ;
187
+
188
+ return tokens . length ;
197
189
}
198
190
199
191
get classes ( ) {
0 commit comments