@@ -65,7 +65,23 @@ const metadata = {
65
65
} ,
66
66
67
67
_items : {
68
- type : Object ,
68
+ type : String ,
69
+ multiple : true ,
70
+ } ,
71
+
72
+ _itemsToShow : {
73
+ type : String ,
74
+ multiple : true ,
75
+ } ,
76
+
77
+ /**
78
+ * Indicates if the wheelslider has a cyclic behaviour.
79
+ * @type {boolean }
80
+ * @defaultvalue false
81
+ * @public
82
+ */
83
+ cyclic : {
84
+ type : Boolean ,
69
85
} ,
70
86
} ,
71
87
slots : /** @lends sap.ui.webcomponents.main.WheelSlider.prototype */ {
@@ -135,9 +151,20 @@ class WheelSlider extends UI5Element {
135
151
super ( ) ;
136
152
this . _currentElementIndex = 0 ;
137
153
this . _itemCellHeight = 0 ;
154
+ this . _itemsToShow = [ ] ;
138
155
}
139
156
140
157
onBeforeRendering ( ) {
158
+ if ( ! this . _expanded && this . cyclic ) {
159
+ const index = this . _currentElementIndex % this . _items . length ;
160
+ this . _currentElementIndex = ( this . _timesMultipliedOnCyclic ( ) / 2 ) * this . _items . length + index ;
161
+ }
162
+
163
+ if ( ! this . value ) {
164
+ this . value = this . _items [ 0 ] ;
165
+ }
166
+
167
+ this . _buildItemsToShow ( ) ;
141
168
this . _updateItemCellHeight ( ) ;
142
169
}
143
170
@@ -154,7 +181,7 @@ class WheelSlider extends UI5Element {
154
181
const elements = this . shadowRoot . querySelectorAll ( ".ui5-wheelslider-item" ) ;
155
182
for ( let i = 0 ; i < elements . length ; i ++ ) {
156
183
if ( elements [ i ] . textContent === this . value ) {
157
- this . _selectElement ( elements [ i ] ) ;
184
+ this . _selectElementByIndex ( Number ( elements [ i ] . dataset . itemIndex ) + this . _getCurrentRepetition ( ) * this . _items . length ) ;
158
185
return true ;
159
186
}
160
187
}
@@ -163,8 +190,23 @@ class WheelSlider extends UI5Element {
163
190
}
164
191
}
165
192
166
- get items ( ) {
167
- return this . _items || [ ] ;
193
+ _timesMultipliedOnCyclic ( ) {
194
+ const minElementsInCyclicWheelSlider = 70 ;
195
+ const repetitionCount = Math . round ( minElementsInCyclicWheelSlider / this . _items . length ) ;
196
+ const minRepetitionCount = 3 ;
197
+
198
+ return Math . max ( minRepetitionCount , repetitionCount ) ;
199
+ }
200
+
201
+ _buildItemsToShow ( ) {
202
+ this . _itemsToShow = this . _items ;
203
+ if ( this . cyclic ) {
204
+ if ( this . _itemsToShow . length < this . _items . length * this . _timesMultipliedOnCyclic ( ) ) {
205
+ for ( let i = 0 ; i < this . _timesMultipliedOnCyclic ( ) ; i ++ ) {
206
+ this . _itemsToShow = this . _itemsToShow . concat ( this . _items ) ;
207
+ }
208
+ }
209
+ }
168
210
}
169
211
170
212
get classes ( ) {
@@ -223,26 +265,53 @@ class WheelSlider extends UI5Element {
223
265
224
266
_selectElement ( element ) {
225
267
if ( element && this . _items . indexOf ( element . textContent ) > - 1 ) {
226
- this . _currentElementIndex = this . _items . indexOf ( element . textContent ) ;
268
+ this . _currentElementIndex = Number ( element . dataset . itemIndex ) ;
227
269
this . _selectElementByIndex ( this . _currentElementIndex ) ;
228
270
}
229
271
}
230
272
231
- _selectElementByIndex ( index ) {
273
+ _getCurrentRepetition ( ) {
274
+ if ( this . _currentElementIndex ) {
275
+ return Math . floor ( this . _currentElementIndex / this . _items . length ) ;
276
+ }
277
+
278
+ return 0 ;
279
+ }
280
+
281
+ _selectElementByIndex ( currentIndex ) {
232
282
const sliderElement = this . shadowRoot . getElementById ( `${ this . _id } --items-list` ) ;
233
- const itemsCount = this . _items . length ;
283
+ const itemsCount = this . _itemsToShow . length ;
234
284
const itemCellHeight = this . _itemCellHeight ? this . _itemCellHeight : 2.875 ;
235
285
const offsetStep = isPhone ( ) ? 4 : 2 ;
286
+ let index = currentIndex ;
287
+
288
+ if ( this . cyclic ) {
289
+ index = this . handleArrayBorderReached ( index ) ;
290
+ }
236
291
237
292
if ( index < itemsCount && index > - 1 ) {
238
293
const offsetSelectedElement = offsetStep * itemCellHeight - ( index * itemCellHeight ) ;
239
294
sliderElement . setAttribute ( "style" , `top:${ offsetSelectedElement } rem` ) ;
240
- this . value = this . _items [ index ] ;
241
295
this . _currentElementIndex = index ;
296
+ this . value = this . _items [ index - ( this . _getCurrentRepetition ( ) * this . _items . length ) ] ;
242
297
this . fireEvent ( "valueSelect" , { value : this . value } ) ;
243
298
}
244
299
}
245
300
301
+ handleArrayBorderReached ( currentIndex ) {
302
+ const arrayLength = this . _itemsToShow . length ;
303
+ const maxVisibleElementsOnOneSide = 5 ;
304
+ let index = currentIndex ;
305
+
306
+ if ( maxVisibleElementsOnOneSide > index ) {
307
+ index += this . _items . length * 2 ;
308
+ } else if ( index > arrayLength - maxVisibleElementsOnOneSide ) {
309
+ index -= this . _items . length * 2 ;
310
+ }
311
+
312
+ return index ;
313
+ }
314
+
246
315
_onArrowDown ( e ) {
247
316
e . preventDefault ( ) ;
248
317
const nextElementIndex = this . _currentElementIndex + 1 ;
0 commit comments