@@ -48,7 +48,6 @@ import {
48
48
LIST_ITEM_POSITION ,
49
49
SELECT_ROLE_DESCRIPTION ,
50
50
} from "./generated/i18n/i18n-defaults.js" ;
51
- import Option from "./Option.js" ;
52
51
import Label from "./Label.js" ;
53
52
import ResponsivePopover from "./ResponsivePopover.js" ;
54
53
import Popover from "./Popover.js" ;
@@ -67,11 +66,27 @@ import selectCss from "./generated/themes/Select.css.js";
67
66
import type FormSupport from "./features/InputElementsFormSupport.js" ;
68
67
import type { IFormElement , NativeFormElement } from "./features/InputElementsFormSupport.js" ;
69
68
69
+ /**
70
+ * Interface for components that may be slotted inside `ui5-select` as options
71
+ * @public
72
+ */
73
+ interface IOption extends UI5Element {
74
+ selected : boolean ,
75
+ tooltip : string ,
76
+ icon ?: string | null ,
77
+ value : string ,
78
+ additionalText ?: string ,
79
+ focused ?: boolean ,
80
+ text ?: Array < Node > ,
81
+ stableDomRef : string ,
82
+ displayText ?: string ,
83
+ }
84
+
70
85
type SelectChangeEventDetail = {
71
- selectedOption : Option ,
86
+ selectedOption : IOption ,
72
87
}
73
88
type SelectLiveChangeEventDetail = {
74
- selectedOption : Option ,
89
+ selectedOption : IOption ,
75
90
}
76
91
77
92
/**
@@ -85,10 +100,10 @@ type SelectLiveChangeEventDetail = {
85
100
*
86
101
* There are two main usages of the `ui5-select>`.
87
102
*
88
- * 1. With Option (`ui5-option`) web component:
103
+ * 1. With IOption (`ui5-option`) web component:
89
104
*
90
- * The available options of the Select are defined by using the Option component.
91
- * The Option comes with predefined design and layout, including `icon`, `text` and `additional-text`.
105
+ * The available options of the Select are defined by using the IOption component.
106
+ * The IOption comes with predefined design and layout, including `icon`, `text` and `additional-text`.
92
107
*
93
108
* ### Keyboard Handling
94
109
* The `ui5-select` provides advanced keyboard handling.
@@ -103,7 +118,7 @@ type SelectLiveChangeEventDetail = {
103
118
* ### ES6 Module Import
104
119
* `import "@ui5/webcomponents/dist/Select";`
105
120
*
106
- * `import "@ui5/webcomponents/dist/Option ";` (comes with `ui5-select`)
121
+ * `import "@ui5/webcomponents/dist/IOption ";` (comes with `ui5-select`)
107
122
* @constructor
108
123
* @extends UI5Element
109
124
* @public
@@ -121,7 +136,6 @@ type SelectLiveChangeEventDetail = {
121
136
SelectPopoverCss ,
122
137
] ,
123
138
dependencies : [
124
- Option ,
125
139
Label ,
126
140
ResponsivePopover ,
127
141
Popover ,
@@ -134,7 +148,7 @@ type SelectLiveChangeEventDetail = {
134
148
/**
135
149
* Fired when the selected option changes.
136
150
* @allowPreventDefault
137
- * @param {Option } selectedOption the selected option.
151
+ * @param {IOption } selectedOption the selected option.
138
152
* @public
139
153
*/
140
154
@event < SelectChangeEventDetail > ( "change" , {
@@ -148,7 +162,7 @@ type SelectLiveChangeEventDetail = {
148
162
/**
149
163
* Fired when the user navigates through the options, but the selection is not finalized,
150
164
* or when pressing the ESC key to revert the current selection.
151
- * @param {Option } selectedOption the selected option.
165
+ * @param {IOption } selectedOption the selected option.
152
166
* @public
153
167
* @since 1.17.0
154
168
*/
@@ -278,7 +292,7 @@ class Select extends UI5Element implements IFormElement {
278
292
279
293
_selectedIndexBeforeOpen : number ;
280
294
_escapePressed : boolean ;
281
- _lastSelectedOption : Option | null ;
295
+ _lastSelectedOption : IOption | null ;
282
296
_typedChars : string ;
283
297
_typingTimeoutID ?: Timeout | number ;
284
298
responsivePopover ! : ResponsivePopover ;
@@ -299,7 +313,7 @@ class Select extends UI5Element implements IFormElement {
299
313
individualSlots : true ,
300
314
invalidateOnChildChange : true ,
301
315
} )
302
- options ! : Array < Option > ;
316
+ options ! : Array < IOption > ;
303
317
304
318
/**
305
319
* The slot is used to render native `input` HTML element within Light DOM to enable form submit,
@@ -413,7 +427,7 @@ class Select extends UI5Element implements IFormElement {
413
427
* @formEvents change liveChange
414
428
*/
415
429
set value ( newValue : string ) {
416
- const options = Array . from ( this . children ) as Array < Option > ;
430
+ const options = Array . from ( this . children ) as Array < IOption > ;
417
431
418
432
options . forEach ( option => {
419
433
option . selected = ! ! ( ( option . getAttribute ( "value" ) || option . textContent ) === newValue ) ;
@@ -433,12 +447,12 @@ class Select extends UI5Element implements IFormElement {
433
447
* @public
434
448
* @default undefined
435
449
*/
436
- get selectedOption ( ) : Option | undefined {
450
+ get selectedOption ( ) : IOption | undefined {
437
451
return this . options . find ( option => option . selected ) ;
438
452
}
439
453
440
454
get text ( ) {
441
- return this . _text || this . selectedOption ?. textContent || "" ;
455
+ return this . _text || this . selectedOption ?. displayText || this . selectedOption ?. textContent || "" ;
442
456
}
443
457
444
458
_toggleRespPopover ( ) {
@@ -539,7 +553,7 @@ class Select extends UI5Element implements IFormElement {
539
553
540
554
orderedOptions = optionsAfterSelected . concat ( optionsBeforeSelected ) ;
541
555
542
- return orderedOptions . find ( option => ( option . textContent || "" ) . toLowerCase ( ) . startsWith ( text ) ) ;
556
+ return orderedOptions . find ( option => ( option . displayText || option . textContent || "" ) . toLowerCase ( ) . startsWith ( text ) ) ;
543
557
}
544
558
545
559
_handleHomeKey ( e : KeyboardEvent ) {
@@ -573,7 +587,7 @@ class Select extends UI5Element implements IFormElement {
573
587
}
574
588
}
575
589
576
- _getItemIndex ( item : Option ) {
590
+ _getItemIndex ( item : IOption ) {
577
591
return this . options . indexOf ( item ) ;
578
592
}
579
593
@@ -676,7 +690,7 @@ class Select extends UI5Element implements IFormElement {
676
690
}
677
691
678
692
_changeSelectedItem ( oldIndex : number , newIndex : number ) {
679
- const options : Array < Option > = this . options ;
693
+ const options : Array < IOption > = this . options ;
680
694
681
695
const previousOption = options [ oldIndex ] ;
682
696
previousOption . selected = false ;
@@ -740,7 +754,7 @@ class Select extends UI5Element implements IFormElement {
740
754
return ! ! this . label . length ;
741
755
}
742
756
743
- _fireChangeEvent ( selectedOption : Option ) {
757
+ _fireChangeEvent ( selectedOption : IOption ) {
744
758
const changePrevented = ! this . fireEvent < SelectChangeEventDetail > ( "change" , { selectedOption } , true ) ;
745
759
746
760
// Angular two way data binding
@@ -942,5 +956,5 @@ export default Select;
942
956
export type {
943
957
SelectChangeEventDetail ,
944
958
SelectLiveChangeEventDetail ,
945
- Option ,
959
+ IOption ,
946
960
} ;
0 commit comments