Skip to content

Commit 52d4a87

Browse files
committed
fix: restore displayText property
1 parent 261e420 commit 52d4a87

File tree

5 files changed

+56
-24
lines changed

5 files changed

+56
-24
lines changed

packages/main/src/Option.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import customElement from "@ui5/webcomponents-base/dist/decorators/customElement
22
import property from "@ui5/webcomponents-base/dist/decorators/property.js";
33

44
import OptionBase from "./OptionBase.js";
5+
import { IOption } from "./Select.js";
56

67
/**
78
* @class
@@ -20,7 +21,7 @@ import OptionBase from "./OptionBase.js";
2021
@customElement({
2122
tag: "ui5-option",
2223
})
23-
class Option extends OptionBase {
24+
class Option extends OptionBase implements IOption {
2425
/**
2526
* Defines the `icon` source URI.
2627
*

packages/main/src/OptionCustom.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import customElement from "@ui5/webcomponents-base/dist/decorators/customElement.js";
2+
import property from "@ui5/webcomponents-base/dist/decorators/property.js";
23

34
import OptionBase from "./OptionBase.js";
45
import optionCustomCss from "./generated/themes/OptionCustom.css.js";
6+
import { IOption } from "./Select.js";
57

68
/**
79
* @class
@@ -25,7 +27,16 @@ import optionCustomCss from "./generated/themes/OptionCustom.css.js";
2527
optionCustomCss,
2628
],
2729
})
28-
class OptionCustom extends OptionBase {
30+
class OptionCustom extends OptionBase implements IOption {
31+
/**
32+
* Defines the text, displayed inside the `ui5-select` input filed
33+
* when the option gets selected.
34+
* @default ""
35+
* @public
36+
*/
37+
@property()
38+
displayText!: string;
39+
2940
get isCustom() {
3041
return true;
3142
}

packages/main/src/Select.ts

+34-20
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ import {
4848
LIST_ITEM_POSITION,
4949
SELECT_ROLE_DESCRIPTION,
5050
} from "./generated/i18n/i18n-defaults.js";
51-
import Option from "./Option.js";
5251
import Label from "./Label.js";
5352
import ResponsivePopover from "./ResponsivePopover.js";
5453
import Popover from "./Popover.js";
@@ -67,11 +66,27 @@ import selectCss from "./generated/themes/Select.css.js";
6766
import type FormSupport from "./features/InputElementsFormSupport.js";
6867
import type { IFormElement, NativeFormElement } from "./features/InputElementsFormSupport.js";
6968

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+
7085
type SelectChangeEventDetail = {
71-
selectedOption: Option,
86+
selectedOption: IOption,
7287
}
7388
type SelectLiveChangeEventDetail = {
74-
selectedOption: Option,
89+
selectedOption: IOption,
7590
}
7691

7792
/**
@@ -85,10 +100,10 @@ type SelectLiveChangeEventDetail = {
85100
*
86101
* There are two main usages of the `ui5-select>`.
87102
*
88-
* 1. With Option (`ui5-option`) web component:
103+
* 1. With IOption (`ui5-option`) web component:
89104
*
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`.
92107
*
93108
* ### Keyboard Handling
94109
* The `ui5-select` provides advanced keyboard handling.
@@ -103,7 +118,7 @@ type SelectLiveChangeEventDetail = {
103118
* ### ES6 Module Import
104119
* `import "@ui5/webcomponents/dist/Select";`
105120
*
106-
* `import "@ui5/webcomponents/dist/Option";` (comes with `ui5-select`)
121+
* `import "@ui5/webcomponents/dist/IOption";` (comes with `ui5-select`)
107122
* @constructor
108123
* @extends UI5Element
109124
* @public
@@ -121,7 +136,6 @@ type SelectLiveChangeEventDetail = {
121136
SelectPopoverCss,
122137
],
123138
dependencies: [
124-
Option,
125139
Label,
126140
ResponsivePopover,
127141
Popover,
@@ -134,7 +148,7 @@ type SelectLiveChangeEventDetail = {
134148
/**
135149
* Fired when the selected option changes.
136150
* @allowPreventDefault
137-
* @param {Option} selectedOption the selected option.
151+
* @param {IOption} selectedOption the selected option.
138152
* @public
139153
*/
140154
@event<SelectChangeEventDetail>("change", {
@@ -148,7 +162,7 @@ type SelectLiveChangeEventDetail = {
148162
/**
149163
* Fired when the user navigates through the options, but the selection is not finalized,
150164
* 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.
152166
* @public
153167
* @since 1.17.0
154168
*/
@@ -278,7 +292,7 @@ class Select extends UI5Element implements IFormElement {
278292

279293
_selectedIndexBeforeOpen: number;
280294
_escapePressed: boolean;
281-
_lastSelectedOption: Option | null;
295+
_lastSelectedOption: IOption | null;
282296
_typedChars: string;
283297
_typingTimeoutID?: Timeout | number;
284298
responsivePopover!: ResponsivePopover;
@@ -299,7 +313,7 @@ class Select extends UI5Element implements IFormElement {
299313
individualSlots: true,
300314
invalidateOnChildChange: true,
301315
})
302-
options!: Array<Option>;
316+
options!: Array<IOption>;
303317

304318
/**
305319
* 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 {
413427
* @formEvents change liveChange
414428
*/
415429
set value(newValue: string) {
416-
const options = Array.from(this.children) as Array<Option>;
430+
const options = Array.from(this.children) as Array<IOption>;
417431

418432
options.forEach(option => {
419433
option.selected = !!((option.getAttribute("value") || option.textContent) === newValue);
@@ -433,12 +447,12 @@ class Select extends UI5Element implements IFormElement {
433447
* @public
434448
* @default undefined
435449
*/
436-
get selectedOption(): Option | undefined {
450+
get selectedOption(): IOption | undefined {
437451
return this.options.find(option => option.selected);
438452
}
439453

440454
get text() {
441-
return this._text || this.selectedOption?.textContent || "";
455+
return this._text || this.selectedOption?.displayText || this.selectedOption?.textContent || "";
442456
}
443457

444458
_toggleRespPopover() {
@@ -539,7 +553,7 @@ class Select extends UI5Element implements IFormElement {
539553

540554
orderedOptions = optionsAfterSelected.concat(optionsBeforeSelected);
541555

542-
return orderedOptions.find(option => (option.textContent || "").toLowerCase().startsWith(text));
556+
return orderedOptions.find(option => (option.displayText || option.textContent || "").toLowerCase().startsWith(text));
543557
}
544558

545559
_handleHomeKey(e: KeyboardEvent) {
@@ -573,7 +587,7 @@ class Select extends UI5Element implements IFormElement {
573587
}
574588
}
575589

576-
_getItemIndex(item: Option) {
590+
_getItemIndex(item: IOption) {
577591
return this.options.indexOf(item);
578592
}
579593

@@ -676,7 +690,7 @@ class Select extends UI5Element implements IFormElement {
676690
}
677691

678692
_changeSelectedItem(oldIndex: number, newIndex: number) {
679-
const options: Array<Option> = this.options;
693+
const options: Array<IOption> = this.options;
680694

681695
const previousOption = options[oldIndex];
682696
previousOption.selected = false;
@@ -740,7 +754,7 @@ class Select extends UI5Element implements IFormElement {
740754
return !!this.label.length;
741755
}
742756

743-
_fireChangeEvent(selectedOption: Option) {
757+
_fireChangeEvent(selectedOption: IOption) {
744758
const changePrevented = !this.fireEvent<SelectChangeEventDetail>("change", { selectedOption }, true);
745759

746760
// Angular two way data binding
@@ -942,5 +956,5 @@ export default Select;
942956
export type {
943957
SelectChangeEventDetail,
944958
SelectLiveChangeEventDetail,
945-
Option,
959+
IOption,
946960
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
slug: ../../OptionCustom
3+
---
4+
5+
<%COMPONENT_OVERVIEW%>
6+
7+
<%COMPONENT_METADATA%>

packages/website/docs/_components_pages/main/Select/Select.mdx

+1-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ Options can dispplay additional text.
2929

3030

3131
### Custom Options
32-
You can define completely custom options via the ui5-select-menu (defining external dropdown)
33-
and ui5-select-menu-option (providing custom content) components.
32+
You can define completely custom options via the ui5-option-custom (providing custom content) component.
3433

3534
<CustomOptions />

0 commit comments

Comments
 (0)