Skip to content

Commit f1bceea

Browse files
authoredNov 12, 2019
fix(ui5-select): remove unsupported method in ie (#919)
1 parent ffdc271 commit f1bceea

File tree

6 files changed

+57
-10
lines changed

6 files changed

+57
-10
lines changed
 

‎packages/base/src/config/CalendarType.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const calendarType = getConfiguredCalendarType();
55

66
const getCalendarType = () => {
77
if (calendarType) {
8-
const type = Object.keys(CalendarType).filter(calType => calType === calendarType)[0];
8+
const type = Object.keys(CalendarType).find(calType => calType === calendarType);
99

1010
if (type) {
1111
return type;

‎packages/base/src/features/browsersupport/IE11.js

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import "../../thirdparty/Object.entries.js";
66

77
// Array
88
import "../../thirdparty/Array.prototype.fill.js";
9+
import "../../thirdparty/Array.prototype.find.js";
910
import "../../thirdparty/Array.prototype.includes.js";
1011

1112
// Number
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// https://tc39.github.io/ecma262/#sec-array.prototype.find
2+
if (!Array.prototype.find) {
3+
Object.defineProperty(Array.prototype, 'find', {
4+
value: function (predicate) {
5+
// 1. Let O be ? ToObject(this value).
6+
if (this == null) {
7+
throw TypeError('"this" is null or not defined');
8+
}
9+
10+
var o = Object(this);
11+
12+
// 2. Let len be ? ToLength(? Get(O, "length")).
13+
var len = o.length >>> 0;
14+
15+
// 3. If IsCallable(predicate) is false, throw a TypeError exception.
16+
if (typeof predicate !== 'function') {
17+
throw TypeError('predicate must be a function');
18+
}
19+
20+
// 4. If thisArg was supplied, let T be thisArg; else let T be undefined.
21+
var thisArg = arguments[1];
22+
23+
// 5. Let k be 0.
24+
var k = 0;
25+
26+
// 6. Repeat, while k < len
27+
while (k < len) {
28+
// a. Let Pk be ! ToString(k).
29+
// b. Let kValue be ? Get(O, Pk).
30+
// c. Let testResult be ToBoolean(? Call(predicate, T, « kValue, k, O »)).
31+
// d. If testResult is true, return kValue.
32+
var kValue = o[k];
33+
if (predicate.call(thisArg, kValue, k, o)) {
34+
return kValue;
35+
}
36+
// e. Increase k by 1.
37+
k++;
38+
}
39+
40+
// 7. Return undefined.
41+
return undefined;
42+
},
43+
configurable: true,
44+
writable: true
45+
});
46+
}

‎packages/base/src/util/TabbableElements.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const getTabbables = (nodes, tabbables) => {
2121
if (currentNode.shadowRoot) {
2222
// get the root node of the ShadowDom (1st none style tag)
2323
const children = currentNode.shadowRoot.children;
24-
currentNode = Array.from(children).filter(node => node.tagName !== "STYLE")[0];
24+
currentNode = Array.from(children).find(node => node.tagName !== "STYLE");
2525
}
2626

2727
if (isNodeTabbable(currentNode)) {

‎packages/main/src/MultiComboBox.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ class MultiComboBox extends UI5Element {
325325

326326
_tokenDelete(event) {
327327
const token = event.detail.ref;
328-
const deletingItem = this.items.filter(item => item._id === token.getAttribute("data-ui5-id"))[0];
328+
const deletingItem = this.items.find(item => item._id === token.getAttribute("data-ui5-id"));
329329

330330
deletingItem.selected = false;
331331
this._deleting = true;

‎packages/main/src/ShellBar.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,9 @@ class ShellBar extends UI5Element {
403403

404404
this._itemNav.setItemsCallback = items => {
405405
const newItems = that._itemsInfo.map(stateItem => {
406-
const mappingItem = items.filter(item => {
406+
const mappingItem = items.find(item => {
407407
return item.id === stateItem.id;
408-
})[0];
408+
});
409409

410410
const clone = JSON.parse(JSON.stringify(stateItem));
411411
clone._tabIndex = mappingItem ? mappingItem._tabIndex : "-1";
@@ -483,7 +483,7 @@ class ShellBar extends UI5Element {
483483
const width = this.getBoundingClientRect().width;
484484
const breakpoints = ShellBar.FIORI_3_BREAKPOINTS;
485485

486-
const size = breakpoints.filter(bp1 => width < bp1)[0] || ShellBar.FIORI_3_BREAKPOINTS[ShellBar.FIORI_3_BREAKPOINTS.length - 1];
486+
const size = breakpoints.find(bp1 => width < bp1) || ShellBar.FIORI_3_BREAKPOINTS[ShellBar.FIORI_3_BREAKPOINTS.length - 1];
487487
const mappedSize = ShellBar.FIORI_3_BREAKPOINTS_MAP[size];
488488

489489
if (this.breakpointSize !== mappedSize) {
@@ -583,11 +583,11 @@ class ShellBar extends UI5Element {
583583
return 1;
584584
});
585585

586-
const focusedItem = items.filter(item => {
586+
const focusedItem = items.find(item => {
587587
return (item.classes.indexOf("ui5-shellbar-invisible-button") === -1)
588588
&& (item.classes.indexOf("ui5-shellbar-overflow-button") === -1)
589589
&& (item.classes.indexOf("ui5-shellbar-hidden-button") === -1);
590-
})[0];
590+
});
591591

592592
return focusedItem;
593593
}
@@ -680,9 +680,9 @@ class ShellBar extends UI5Element {
680680
this._itemNav.currentIndex = elementIndex;
681681

682682
if (refItemId) {
683-
const shellbarItem = this.items.filter(item => {
683+
const shellbarItem = this.items.find(item => {
684684
return item.shadowRoot.querySelector(`#${refItemId}`);
685-
})[0];
685+
});
686686

687687
const prevented = !shellbarItem.fireEvent("itemClick", { targetRef: event.target }, true);
688688

0 commit comments

Comments
 (0)
Please sign in to comment.