Skip to content

Commit 2e4486b

Browse files
MapTo0vladitasev
authored andcommitted
refactor(ui5-select): change default slot from list items to options (#532)
This change makes the ui5-select web component use dedicated items: ui5-option instead of ui5-li BREAKING CHANGE: Use ui5-option instead of ui5-li in ui5-select
1 parent d641cce commit 2e4486b

File tree

12 files changed

+355
-284
lines changed

12 files changed

+355
-284
lines changed

packages/base/src/UI5Element.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class UI5Element extends HTMLElement {
3939
}
4040

4141
onThemeChanged() {
42-
if (window.ShadyDOM) {
42+
if (window.ShadyDOM || this.constructor.getMetadata().getNoShadowDOM()) {
4343
// polyfill theme handling is in head styles directly
4444
return;
4545
}

packages/main/bundle.esm.js

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import Popover from "./dist/Popover.js";
2626
import Panel from "./dist/Panel.js";
2727
import RadioButton from "./dist/RadioButton.js";
2828
import Select from "./dist/Select.js";
29+
import Option from "./dist/Option.js";
2930
import ShellBar from "./dist/ShellBar.js";
3031
import ShellBarItem from "./dist/ShellBarItem.js";
3132
import Switch from "./dist/Switch.js";

packages/main/src/ListItem.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,14 @@ class ListItem extends ListItemBase {
8080
return [styles, ListItemBase.styles];
8181
}
8282

83-
constructor() {
84-
super();
83+
constructor(props) {
84+
super(props);
85+
86+
this.deactivateByKey = event => {
87+
if (isEnter(event)) {
88+
this.deactivate();
89+
}
90+
};
8591

8692
this.deactivate = () => {
8793
if (this._active) {
@@ -94,10 +100,12 @@ class ListItem extends ListItemBase {
94100

95101
onEnterDOM() {
96102
document.addEventListener("mouseup", this.deactivate);
103+
document.addEventListener("keyup", this.deactivateByKey);
97104
}
98105

99106
onExitDOM() {
100107
document.removeEventListener("mouseup", this.deactivate);
108+
document.removeEventListener("keyup", this.deactivateByKey);
101109
}
102110

103111
onkeydown(event) {

packages/main/src/Option.js

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import UI5Element from "@ui5/webcomponents-base/src/UI5Element.js";
2+
import Bootstrap from "@ui5/webcomponents-base/src/Bootstrap.js";
3+
4+
/**
5+
* @public
6+
*/
7+
const metadata = {
8+
tag: "ui5-option",
9+
noShadowDOM: true,
10+
properties: /** @lends sap.ui.webcomponents.main.Option.prototype */ {
11+
12+
/**
13+
* Defines the selected state of the <code>ui5-option</code>.
14+
* @type {boolean}
15+
* @defaultvalue false
16+
* @public
17+
*/
18+
selected: {
19+
type: Boolean,
20+
},
21+
22+
/**
23+
* Defines the <code>icon</code> source URI.
24+
* </br></br>
25+
* <b>Note:</b>
26+
* SAP-icons font provides numerous buil-in icons. To find all the available icons, see the
27+
* <ui5-link target="_blank" href="https://openui5.hana.ondemand.com/test-resources/sap/m/demokit/iconExplorer/webapp/index.html" class="api-table-content-cell-link">Icon Explorer</ui5-link>.
28+
*
29+
* @type {string}
30+
* @public
31+
*/
32+
icon: {
33+
type: String,
34+
defaultValue: null,
35+
},
36+
},
37+
38+
events: /** @lends sap.ui.webcomponents.main.Option.prototype */ {},
39+
};
40+
41+
/**
42+
* @class
43+
*
44+
* <h3 class="comment-api-title">Overview</h3>
45+
*
46+
* The <code>ui5-option</code> component defines the content of an opton in the <code>ui5-select</code>.
47+
*
48+
* @constructor
49+
* @author SAP SE
50+
* @alias sap.ui.webcomponents.main.Option
51+
* @extends sap.ui.webcomponents.base.UI5Element
52+
* @tagname ui5-option
53+
* @public
54+
*/
55+
class Option extends UI5Element {
56+
static get metadata() {
57+
return metadata;
58+
}
59+
}
60+
61+
Bootstrap.boot().then(_ => {
62+
Option.define();
63+
});
64+
65+
export default Option;

packages/main/src/Select.hbs

+17-6
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,39 @@
22
class="{{classes.main}}"
33
tabindex="{{tabIndex}}"
44
dir="{{rtl}}"
5+
@keydown="{{_keydown}}"
6+
@keyup="{{_keyup}}"
57
>
68
<div
79
class="sapWCSelectLabel"
8-
@click="{{toggleList}}">
10+
@click="{{_togglePopover}}">
911
<ui5-label>{{_text}}</ui5-label>
1012
</div>
1113

12-
{{#if items}}
14+
{{#if options}}
1315
<ui5-popover
16+
id="ui5-select--popover"
1417
placement-type="Bottom"
1518
no-header
1619
no-arrow
17-
horizontal-align="Stretch">
18-
<ui5-list separators="None">
19-
<slot></slot>
20+
horizontal-align="Stretch"
21+
@ui5-afterOpen="{{_applyFocusAfterOpen}}"
22+
@ui5-beforeOpen="{{_beforeOpen}}"
23+
@ui5-afterClose="{{_afterClose}}"
24+
>
25+
<ui5-list mode="SingleSelect" separators="None" @keydown="{{_handlePickerKeydown}}" @ui5-itemPress="{{_selectionChange}}">
26+
{{#each _syncedOptions}}
27+
<ui5-li ?selected="{{this.selected}}" icon="{{this.icon}}" id="{{this.id}}-li">
28+
{{this.textContent}}
29+
</ui5-li>
30+
{{/each}}
2031
</ui5-list>
2132
</ui5-popover>
2233
{{/if}}
2334

2435
<ui5-icon
2536
src="sap-icon://slim-arrow-down"
2637
class="sapWCSelectDropDownIcon"
27-
@ui5-press="{{toggleList}}"
38+
@ui5-press="{{_togglePopover}}"
2839
></ui5-icon>
2940
</div>

0 commit comments

Comments
 (0)