1
1
import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js" ;
2
2
import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js" ;
3
3
import ValueState from "@ui5/webcomponents-base/dist/types/ValueState.js" ;
4
- import { isShow , isDown } from "@ui5/webcomponents-base/dist/events/PseudoEvents.js" ;
4
+ import { isShow , isDown , isBackSpace } from "@ui5/webcomponents-base/dist/events/PseudoEvents.js" ;
5
5
import "./icons/slim-arrow-down.js" ;
6
6
import MultiComboBoxTemplate from "./generated/templates/MultiComboBoxTemplate.lit.js" ;
7
7
import Input from "./Input.js" ;
@@ -121,6 +121,14 @@ const metadata = {
121
121
type : Boolean ,
122
122
} ,
123
123
124
+ /**
125
+ * Indicates whether the input is focssed
126
+ * @private
127
+ */
128
+ focused : {
129
+ type : Boolean ,
130
+ } ,
131
+
124
132
_filteredItems : {
125
133
type : Object ,
126
134
} ,
@@ -129,6 +137,14 @@ const metadata = {
129
137
type : Boolean ,
130
138
noAttribute : true ,
131
139
} ,
140
+
141
+ /**
142
+ * Indicates whether the tokenizer is expanded or collapsed(shows the n more label)
143
+ * @private
144
+ */
145
+ expandedTokenizer : {
146
+ type : Boolean ,
147
+ } ,
132
148
} ,
133
149
events : /** @lends sap.ui.webcomponents.main.MultiComboBox.prototype */ {
134
150
/**
@@ -236,6 +252,7 @@ class MultiComboBox extends UI5Element {
236
252
this . _filteredItems = [ ] ;
237
253
this . _inputLastValue = "" ;
238
254
this . _deleting = false ;
255
+ this . _validationTimeout = null ;
239
256
}
240
257
241
258
_inputChange ( ) {
@@ -248,6 +265,12 @@ class MultiComboBox extends UI5Element {
248
265
249
266
_showAllItemsPopover ( ) {
250
267
this . _togglePopover ( false ) ;
268
+
269
+ this . _inputDom . focus ( ) ;
270
+ }
271
+
272
+ get _inputDom ( ) {
273
+ return this . shadowRoot . querySelector ( "#ui5-multi-combobox-input" ) ;
251
274
}
252
275
253
276
_inputLiveChange ( event ) {
@@ -256,12 +279,17 @@ class MultiComboBox extends UI5Element {
256
279
const filteredItems = this . _filterItems ( value ) ;
257
280
const oldValueState = this . valueState ;
258
281
282
+ if ( this . _validationTimeout ) {
283
+ return ;
284
+ }
285
+
259
286
if ( ! filteredItems . length && value && ! this . allowCustomValues ) {
260
287
input . value = this . _inputLastValue ;
261
- input . valueState = "Error" ;
288
+ this . valueState = "Error" ;
262
289
263
- setTimeout ( ( ) => {
264
- input . valueState = oldValueState ;
290
+ this . _validationTimeout = setTimeout ( ( ) => {
291
+ this . valueState = oldValueState ;
292
+ this . _validationTimeout = null ;
265
293
} , 2000 ) ;
266
294
return ;
267
295
}
@@ -298,11 +326,10 @@ class MultiComboBox extends UI5Element {
298
326
299
327
if ( tokensCount === 0 && this . _deleting ) {
300
328
setTimeout ( ( ) => {
301
- this . shadowRoot . querySelector ( "ui5-input" ) . focus ( ) ;
329
+ this . shadowRoot . querySelector ( "input" ) . focus ( ) ;
330
+ this . _deleting = false ;
302
331
} , 0 ) ;
303
332
}
304
-
305
- this . _deleting = false ;
306
333
}
307
334
308
335
_keydown ( event ) {
@@ -317,6 +344,17 @@ class MultiComboBox extends UI5Element {
317
344
list . _itemNavigation . current = 0 ;
318
345
list . items [ 0 ] . focus ( ) ;
319
346
}
347
+
348
+ if ( isBackSpace ( event ) && event . target . value === "" ) {
349
+ const lastTokenIndex = this . _tokenizer . tokens . length - 1 ;
350
+
351
+ if ( lastTokenIndex < 0 ) {
352
+ return ;
353
+ }
354
+
355
+ this . _tokenizer . tokens [ lastTokenIndex ] . focus ( ) ;
356
+ this . _tokenizer . _itemNav . currentIndex = lastTokenIndex ;
357
+ }
320
358
}
321
359
322
360
_filterItems ( value ) {
@@ -362,6 +400,14 @@ class MultiComboBox extends UI5Element {
362
400
popover && popover . openBy ( this ) ;
363
401
}
364
402
403
+ _focusin ( ) {
404
+ this . focused = true ;
405
+ }
406
+
407
+ _focusout ( ) {
408
+ this . focused = false ;
409
+ }
410
+
365
411
onBeforeRendering ( ) {
366
412
this . _inputLastValue = this . value ;
367
413
@@ -373,7 +419,7 @@ class MultiComboBox extends UI5Element {
373
419
morePopover && morePopover . close ( ) ;
374
420
}
375
421
376
- const input = this . shadowRoot . querySelector ( "ui5- input" ) ;
422
+ const input = this . shadowRoot . querySelector ( "input" ) ;
377
423
378
424
if ( input && ! input . value ) {
379
425
this . _filteredItems = this . items ;
@@ -383,6 +429,19 @@ class MultiComboBox extends UI5Element {
383
429
this . _filteredItems = filteredItems ;
384
430
}
385
431
432
+ get _tokenizer ( ) {
433
+ return this . shadowRoot . querySelector ( "ui5-tokenizer" ) ;
434
+ }
435
+
436
+ rootFocusIn ( ) {
437
+ this . expandedTokenizer = true ;
438
+ }
439
+
440
+ rootFocusOut ( event ) {
441
+ if ( ! this . shadowRoot . contains ( event . relatedTarget ) && ! this . _deleting ) {
442
+ this . expandedTokenizer = false ;
443
+ }
444
+ }
386
445
387
446
get editable ( ) {
388
447
return ! this . readonly ;
@@ -392,15 +451,6 @@ class MultiComboBox extends UI5Element {
392
451
return this . readonly ? "None" : "MultiSelect" ;
393
452
}
394
453
395
- get classes ( ) {
396
- return {
397
- icon : {
398
- [ `ui5-multi-combobox-icon-root-pressed` ] : this . _iconPressed ,
399
- [ `ui5-multi-combobox-icon` ] : true ,
400
- } ,
401
- } ;
402
- }
403
-
404
454
static async define ( ...params ) {
405
455
await Promise . all ( [
406
456
Input . define ( ) ,
0 commit comments