Skip to content

Commit 4cbe3de

Browse files
authored
fix: prevent dual event dispatching in no conflict mode (#363)
- all controls should now listen for prefixed events ui5-* - all test run with no conflict setting, therefore test pages should interact with ui5-* events - both events are now dispatched in normal mode - in no conflict mode - just the prefixed event is dispatched Fixes: #304
1 parent 4b64a9c commit 4cbe3de

39 files changed

+128
-130
lines changed

packages/base/src/Configuration.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ const getWCNoConflict = () => {
3737
return CONFIGURATION["xx-wc-no-conflict"];
3838
};
3939

40+
const _setWCNoConflict = value => {
41+
CONFIGURATION["xx-wc-no-conflict"] = value;
42+
};
43+
4044
/* Calendar stuff */
4145
const getCalendarType = () => {
4246
if (CONFIGURATION.calendarType) {
@@ -125,6 +129,7 @@ export {
125129
getCalendarType,
126130
getLocale,
127131
_setTheme,
132+
_setWCNoConflict,
128133
getSupportedLanguages,
129134
getOriginInfo,
130135
};

packages/base/src/UI5Element.js

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -502,29 +502,32 @@ class UI5Element extends HTMLElement {
502502
*/
503503
fireEvent(name, data, cancelable) {
504504
let compatEventResult = true; // Initialized to true, because if the event is not fired at all, it should be considered "not-prevented"
505+
const noConflict = getWCNoConflict();
505506

506-
let customEvent = new CustomEvent(name, {
507+
const noConflictEvent = new CustomEvent(`ui5-${name}`, {
507508
detail: data,
508509
composed: false,
509510
bubbles: true,
510511
cancelable,
511512
});
512513

513-
// This will be false if the normal event is prevented
514-
const normalEventResult = this.dispatchEvent(customEvent);
514+
// This will be false if the compat event is prevented
515+
compatEventResult = this.dispatchEvent(noConflictEvent);
515516

516-
if (UI5Element.noConflictEvents.includes(name)) {
517-
customEvent = new CustomEvent(`ui5-${name}`, {
518-
detail: data,
519-
composed: false,
520-
bubbles: true,
521-
cancelable,
522-
});
523-
524-
// This will be false if the compat event is prevented
525-
compatEventResult = this.dispatchEvent(customEvent);
517+
if (noConflict === true || (noConflict.events && noConflict.events.includes && noConflict.events.includes(name))) {
518+
return compatEventResult;
526519
}
527520

521+
const customEvent = new CustomEvent(name, {
522+
detail: data,
523+
composed: false,
524+
bubbles: true,
525+
cancelable,
526+
});
527+
528+
// This will be false if the normal event is prevented
529+
const normalEventResult = this.dispatchEvent(customEvent);
530+
528531
// Return false if any of the two events was prevented (its result was false).
529532
return normalEventResult && compatEventResult;
530533
}
@@ -610,18 +613,6 @@ class UI5Element extends HTMLElement {
610613
},
611614
});
612615
}
613-
614-
static get noConflictEvents() {
615-
if (!this._noConflictEvents) {
616-
const noConflictConfig = getWCNoConflict();
617-
this._noConflictEvents = [];
618-
if (typeof noConflictConfig === "object" && typeof noConflictConfig.events === "string") {
619-
this._noConflictEvents = noConflictConfig.events.split(",").map(evtName => evtName.trim());
620-
}
621-
}
622-
623-
return this._noConflictEvents;
624-
}
625616
}
626617
const kebabToCamelCase = string => toCamelCase(string.split("-"));
627618
const camelToKebabCase = string => string.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();

packages/main/src/Calendar.hbs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
month-text="{{ctr._header.monthText}}"
66
year-text="{{ctr._header.yearText}}"
77
.primaryCalendarType="{{ctr._oMonth.primaryCalendarType}}"
8-
@pressPrevious="{{ctr._header.onPressPrevious}}"
9-
@pressNext="{{ctr._header.onPressNext}}"
10-
@btn1Press="{{ctr._header.onBtn1Press}}"
11-
@btn2Press="{{ctr._header.onBtn2Press}}"
8+
@ui5-pressPrevious="{{ctr._header.onPressPrevious}}"
9+
@ui5-pressNext="{{ctr._header.onPressNext}}"
10+
@ui5-btn1Press="{{ctr._header.onBtn1Press}}"
11+
@ui5-btn2Press="{{ctr._header.onBtn2Press}}"
1212
></ui5-calendar-header>
1313

1414
<div id="{{ctr._id}}-content" class="sapUiCalContent">
@@ -20,8 +20,8 @@
2020
._hidden="{{ctr._oMonth._hidden}}"
2121
.primaryCalendarType="{{ctr._oMonth.primaryCalendarType}}"
2222
timestamp="{{ctr._oMonth.timestamp}}"
23-
@selectionChange="{{ctr._oMonth.onSelectedDatesChange}}"
24-
@navigate="{{ctr._oMonth.onNavigate}}"
23+
@ui5-selectionChange="{{ctr._oMonth.onSelectedDatesChange}}"
24+
@ui5-navigate="{{ctr._oMonth.onNavigate}}"
2525
></ui5-daypicker>
2626

2727
<ui5-month-picker
@@ -30,7 +30,7 @@
3030
._hidden="{{ctr._monthPicker._hidden}}"
3131
.primaryCalendarType="{{ctr._oMonth.primaryCalendarType}}"
3232
timestamp="{{ctr._monthPicker.timestamp}}"
33-
@selectedMonthChange="{{ctr._monthPicker.onSelectedMonthChange}}"
33+
@ui5-selectedMonthChange="{{ctr._monthPicker.onSelectedMonthChange}}"
3434
></ui5-month-picker>
3535

3636
<ui5-yearpicker
@@ -40,7 +40,7 @@
4040
.primaryCalendarType="{{ctr._oMonth.primaryCalendarType}}"
4141
timestamp="{{ctr._yearPicker.timestamp}}"
4242
._selectedYear="{{ctr._yearPicker._selectedYear}}"
43-
@selectedYearChange="{{ctr._yearPicker.onSelectedYearChange}}"
43+
@ui5-selectedYearChange="{{ctr._yearPicker.onSelectedYearChange}}"
4444
></ui5-yearpicker>
4545
</div>
4646
</div>

packages/main/src/DatePicker.hbs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
?disabled="{{ctr.disabled}}"
1212
?readonly="{{ctr.readonly}}"
1313
value-state="{{ctr.valueState}}"
14-
@change="{{ctr._input.onChange}}"
15-
@input="{{ctr._input.onLiveChange}}"
14+
@ui5-change="{{ctr._input.onChange}}"
15+
@ui5-input="{{ctr._input.onLiveChange}}"
1616
data-sap-focus-ref
1717
>
1818
{{#if showIcon}}
@@ -35,8 +35,8 @@
3535
horizontal-align="{{ctr._popover.horizontalAlign}}"
3636
stay-open-on-scroll="{{ctr._popover.stayOpenOnScroll}}"
3737
.customClasses="{{ctr._popover._customClasses}}"
38-
@afterClose="{{ctr._popover.afterClose}}"
39-
@afterOpen="{{ctr._popover.afterOpen}}"
38+
@ui5-afterClose="{{ctr._popover.afterClose}}"
39+
@ui5-afterOpen="{{ctr._popover.afterOpen}}"
4040
>
4141
<ui5-calendar
4242
id="{{ctr._id}}-calendar"
@@ -45,7 +45,7 @@
4545
format-pattern="{{ctr._calendar.formatPattern}}"
4646
timestamp="{{ctr._calendar.timestamp}}"
4747
.selectedDates="{{ctr._calendar.selectedDates}}"
48-
@selectedDatesChange="{{ctr._calendar.onSelectedDatesChange}}"
48+
@ui5-selectedDatesChange="{{ctr._calendar.onSelectedDatesChange}}"
4949
></ui5-calendar>
5050
</ui5-popover>
5151

packages/main/src/List.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,11 @@ class List extends UI5Element {
243243

244244
this._previouslySelectedItem = null;
245245

246-
this.addEventListener("_press", this.onItemPress.bind(this));
247-
this.addEventListener("_focused", this.onItemFocused.bind(this));
248-
this.addEventListener("_forwardAfter", this.onForwardAfter.bind(this));
249-
this.addEventListener("_forwardBefore", this.onForwardBefore.bind(this));
250-
this.addEventListener("_selectionRequested", this.onSelectionRequested.bind(this));
246+
this.addEventListener("ui5-_press", this.onItemPress.bind(this));
247+
this.addEventListener("ui5-_focused", this.onItemFocused.bind(this));
248+
this.addEventListener("ui5-_forwardAfter", this.onForwardAfter.bind(this));
249+
this.addEventListener("ui5-_forwardBefore", this.onForwardBefore.bind(this));
250+
this.addEventListener("ui5-_selectionRequested", this.onSelectionRequested.bind(this));
251251
}
252252

253253
onBeforeRendering() {

packages/main/src/ListItem.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
id="{{ctr._id}}-deleteSelectionControl"
4949
type="Transparent"
5050
icon="sap-icon://decline"
51-
@press="{{ctr._fnOnDelete}}"
51+
@ui5-press="{{ctr._fnOnDelete}}"
5252
></ui5-button>
5353
</div>
5454
{{/if}}

packages/main/src/MessageStrip.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
class="{{classes.closeIcon}}"
1111
src="sap-icon://decline"
1212
tabindex="0"
13-
@press="{{ctr._closeButton.press}}">
13+
@ui5-press="{{ctr._closeButton.press}}">
1414
</ui5-icon>
1515
{{/unless}}
1616
</div>

packages/main/src/Panel.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
tabindex="{{iconTabIndex}}"
1717
aria-expanded="{{expanded}}"
1818
aria-labelledby="{{ariaLabelledBy}}"
19-
@press="{{ctr._icon.press}}"
19+
@ui5-press="{{ctr._icon.press}}"
2020
></ui5-icon>
2121
{{> header}}
2222
</header>

packages/main/src/Select.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525
<ui5-icon
2626
src="sap-icon://slim-arrow-down"
2727
class="sapWCSelectDropDownIcon"
28-
@press="{{ctr._fnClickSelectBox}}"
28+
@ui5-press="{{ctr._fnClickSelectBox}}"
2929
></ui5-icon>
3030
</div>

packages/main/src/ShellBar.hbs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
{{/if}}
2828

2929
<ui5-popover class="sapWCShellBarMenuPopover" hide-header placement-type="Bottom">
30-
<ui5-list separators="None" mode="SingleSelect" @itemPress={{ctr._menuItemPress}}>
30+
<ui5-list separators="None" mode="SingleSelect" @ui5-itemPress={{ctr._menuItemPress}}>
3131
{{#each ctr.menuItems}}
3232
<slot name="{{this._slot}}"></slot>
3333
{{/each}}
@@ -58,7 +58,7 @@
5858
src="{{this.src}}"
5959
id="{{this.id}}"
6060
style="{{this.style}}"
61-
@press={{this.press}}>
61+
@ui5-press={{this.press}}>
6262
</ui5-icon>
6363
{{else}}
6464
<div
@@ -76,13 +76,13 @@
7676
</div>
7777

7878
<ui5-popover class="sapWCShellBarOverflowPopover" placement-type="Bottom" horizontal-align="{{popoverHorizontalAlign}}" hide-header hide-arrow>
79-
<ui5-list separators="None" @itemPress="{{ctr._actionList.itemPress}}">
79+
<ui5-list separators="None" @ui5-itemPress="{{ctr._actionList.itemPress}}">
8080
{{#each _hiddenIcons}}
8181
<ui5-li
8282
data-ui5-external-action-item-id="{{this.refItemid}}"
8383
icon="{{this.src}}"
8484
type="Active"
85-
@_press="{{this.press}}"
85+
@ui5-_press="{{this.press}}"
8686
>{{this.text}}
8787
</ui5-li>
8888
{{/each}}

0 commit comments

Comments
 (0)