Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent dual event dispatching in no conflict mode #363

Merged
merged 4 commits into from
May 15, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions packages/base/src/UI5Element.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,29 +496,32 @@ class UI5Element extends HTMLElement {
*/
fireEvent(name, data, cancelable) {
let compatEventResult = true; // Initialized to true, because if the event is not fired at all, it should be considered "not-prevented"
const noConflict = getWCNoConflict();

let customEvent = new CustomEvent(name, {
const conflictEvent = new CustomEvent(`ui5-${name}`, {
MapTo0 marked this conversation as resolved.
Show resolved Hide resolved
detail: data,
composed: false,
bubbles: true,
cancelable,
});

// This will be false if the normal event is prevented
const normalEventResult = this.dispatchEvent(customEvent);

if (UI5Element.noConflictEvents.includes(name)) {
customEvent = new CustomEvent(`ui5-${name}`, {
detail: data,
composed: false,
bubbles: true,
cancelable,
});
// This will be false if the compat event is prevented
compatEventResult = this.dispatchEvent(conflictEvent);

// This will be false if the compat event is prevented
compatEventResult = this.dispatchEvent(customEvent);
if (noConflict) {
return compatEventResult;
}

const customEvent = new CustomEvent(name, {
detail: data,
composed: false,
bubbles: true,
cancelable,
});

// This will be false if the normal event is prevented
const normalEventResult = this.dispatchEvent(customEvent);

// Return false if any of the two events was prevented (its result was false).
return normalEventResult && compatEventResult;
}
Expand Down
16 changes: 8 additions & 8 deletions packages/main/src/Calendar.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
month-text="{{ctr._header.monthText}}"
year-text="{{ctr._header.yearText}}"
.primaryCalendarType="{{ctr._oMonth.primaryCalendarType}}"
@pressPrevious="{{ctr._header.onPressPrevious}}"
@pressNext="{{ctr._header.onPressNext}}"
@btn1Press="{{ctr._header.onBtn1Press}}"
@btn2Press="{{ctr._header.onBtn2Press}}"
@ui5-pressPrevious="{{ctr._header.onPressPrevious}}"
@ui5-pressNext="{{ctr._header.onPressNext}}"
@ui5-btn1Press="{{ctr._header.onBtn1Press}}"
@ui5-btn2Press="{{ctr._header.onBtn2Press}}"
></ui5-calendar-header>

<div id="{{ctr._id}}-content" class="sapUiCalContent">
Expand All @@ -20,8 +20,8 @@
._hidden="{{ctr._oMonth._hidden}}"
.primaryCalendarType="{{ctr._oMonth.primaryCalendarType}}"
timestamp="{{ctr._oMonth.timestamp}}"
@selectionChange="{{ctr._oMonth.onSelectedDatesChange}}"
@navigate="{{ctr._oMonth.onNavigate}}"
@ui5-selectionChange="{{ctr._oMonth.onSelectedDatesChange}}"
@ui5-navigate="{{ctr._oMonth.onNavigate}}"
></ui5-daypicker>

<ui5-month-picker
Expand All @@ -30,7 +30,7 @@
._hidden="{{ctr._monthPicker._hidden}}"
.primaryCalendarType="{{ctr._oMonth.primaryCalendarType}}"
timestamp="{{ctr._monthPicker.timestamp}}"
@selectedMonthChange="{{ctr._monthPicker.onSelectedMonthChange}}"
@ui5-selectedMonthChange="{{ctr._monthPicker.onSelectedMonthChange}}"
></ui5-month-picker>

<ui5-yearpicker
Expand All @@ -40,7 +40,7 @@
.primaryCalendarType="{{ctr._oMonth.primaryCalendarType}}"
timestamp="{{ctr._yearPicker.timestamp}}"
._selectedYear="{{ctr._yearPicker._selectedYear}}"
@selectedYearChange="{{ctr._yearPicker.onSelectedYearChange}}"
@ui5-selectedYearChange="{{ctr._yearPicker.onSelectedYearChange}}"
></ui5-yearpicker>
</div>
</div>
10 changes: 5 additions & 5 deletions packages/main/src/DatePicker.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
?disabled="{{ctr.disabled}}"
?readonly="{{ctr.readonly}}"
value-state="{{ctr.valueState}}"
@change="{{ctr._input.onChange}}"
@input="{{ctr._input.onLiveChange}}"
@ui5-change="{{ctr._input.onChange}}"
@ui5-input="{{ctr._input.onLiveChange}}"
data-sap-focus-ref
>
{{#if showIcon}}
Expand All @@ -35,8 +35,8 @@
horizontal-align="{{ctr._popover.horizontalAlign}}"
stay-open-on-scroll="{{ctr._popover.stayOpenOnScroll}}"
.customClasses="{{ctr._popover._customClasses}}"
@afterClose="{{ctr._popover.afterClose}}"
@afterOpen="{{ctr._popover.afterOpen}}"
@ui5-afterClose="{{ctr._popover.afterClose}}"
@ui5-afterOpen="{{ctr._popover.afterOpen}}"
>
<ui5-calendar
id="{{ctr._id}}-calendar"
Expand All @@ -45,7 +45,7 @@
format-pattern="{{ctr._calendar.formatPattern}}"
timestamp="{{ctr._calendar.timestamp}}"
.selectedDates="{{ctr._calendar.selectedDates}}"
@selectedDatesChange="{{ctr._calendar.onSelectedDatesChange}}"
@ui5-selectedDatesChange="{{ctr._calendar.onSelectedDatesChange}}"
></ui5-calendar>
</ui5-popover>

Expand Down
2 changes: 1 addition & 1 deletion packages/main/src/ListItem.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
id="{{ctr._id}}-deleteSelectionControl"
type="Transparent"
icon="sap-icon://decline"
@press="{{ctr._fnOnDelete}}"
@ui5-press="{{ctr._fnOnDelete}}"
></ui5-button>
</div>
{{/if}}
Expand Down
2 changes: 1 addition & 1 deletion packages/main/src/MessageStrip.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class="{{classes.closeIcon}}"
src="sap-icon://decline"
tabindex="0"
@press="{{ctr._closeButton.press}}">
@ui5-press="{{ctr._closeButton.press}}">
</ui5-icon>
{{/unless}}
</div>
2 changes: 1 addition & 1 deletion packages/main/src/Panel.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
tabindex="{{iconTabIndex}}"
aria-expanded="{{expanded}}"
aria-labelledby="{{ariaLabelledBy}}"
@press="{{ctr._icon.press}}"
@ui5-press="{{ctr._icon.press}}"
></ui5-icon>
{{> header}}
</header>
Expand Down
2 changes: 1 addition & 1 deletion packages/main/src/Select.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
<ui5-icon
src="sap-icon://slim-arrow-down"
class="sapWCSelectDropDownIcon"
@press="{{ctr._fnClickSelectBox}}"
@ui5-press="{{ctr._fnClickSelectBox}}"
></ui5-icon>
</div>
8 changes: 4 additions & 4 deletions packages/main/src/ShellBar.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
{{/if}}

<ui5-popover class="sapWCShellBarMenuPopover" hide-header placement-type="Bottom">
<ui5-list separators="None" mode="SingleSelect" @itemPress={{ctr._menuItemPress}}>
<ui5-list separators="None" mode="SingleSelect" @ui5-itemPress={{ctr._menuItemPress}}>
{{#each ctr.menuItems}}
<slot name="{{this._slot}}"></slot>
{{/each}}
Expand Down Expand Up @@ -58,7 +58,7 @@
src="{{this.src}}"
id="{{this.id}}"
style="{{this.style}}"
@press={{this.press}}>
@ui5-press={{this.press}}>
</ui5-icon>
{{else}}
<div
Expand All @@ -76,13 +76,13 @@
</div>

<ui5-popover class="sapWCShellBarOverflowPopover" placement-type="Bottom" horizontal-align="{{popoverHorizontalAlign}}" hide-header hide-arrow>
<ui5-list separators="None" @itemPress="{{ctr._actionList.itemPress}}">
<ui5-list separators="None" @ui5-itemPress="{{ctr._actionList.itemPress}}">
{{#each _hiddenIcons}}
<ui5-li
data-ui5-external-action-item-id="{{this.refItemid}}"
icon="{{this.src}}"
type="Active"
@_press="{{this.press}}"
@ui5-_press="{{this.press}}"
>{{this.text}}
</ui5-li>
{{/each}}
Expand Down
8 changes: 4 additions & 4 deletions packages/main/src/TabContainer.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div {{> controlData}} class="{{classes.main}}">
<div class="{{classes.header}}" id="{{ctr._id}}-header">
<ui5-icon @press="{{ctr._headerBackArrow.click}}" class="{{classes.headerBackArrow}}" src="sap-icon://slim-arrow-left" tabindex="-1"></ui5-icon>
<ui5-icon @ui5-press="{{ctr._headerBackArrow.click}}" class="{{classes.headerBackArrow}}" src="sap-icon://slim-arrow-left" tabindex="-1"></ui5-icon>

<!-- tab items -->
<div class="{{classes.headerScrollContainer}}" id="{{ctr._id}}-headerScrollContainer">
Expand Down Expand Up @@ -42,12 +42,12 @@
</ul>
</div>

<ui5-icon @press="{{ctr._headerForwardArrow.click}}" class="{{classes.headerForwardArrow}}" src="sap-icon://slim-arrow-right" tabindex="-1"></ui5-icon>
<ui5-icon @ui5-press="{{ctr._headerForwardArrow.click}}" class="{{classes.headerForwardArrow}}" src="sap-icon://slim-arrow-right" tabindex="-1"></ui5-icon>

<!-- overflow button -->
{{#if ctr.showOverflow}}
<ui5-button
@press="{{ctr._overflowButton.click}}"
@ui5-press="{{ctr._overflowButton.click}}"
class="{{classes.overflowButton}}"
icon="sap-icon://slim-arrow-down"
type="Transparent"
Expand All @@ -73,7 +73,7 @@
hide-header
placement-type="Bottom"
horizontal-align="Right">
<ui5-list @itemPress="{{ctr._overflowList.click}}">
<ui5-list @ui5-itemPress="{{ctr._overflowList.click}}">
{{#each renderItems}}
{{#unless this.isSeparator}}
<ui5-li-custom id="{{this.item._id}}"
Expand Down
2 changes: 1 addition & 1 deletion packages/main/src/TimelineItem.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

{{#*inline "itemName"}}
{{#if ctr.itemNameClickable}}
<ui5-link @press="{{ctr._onItemNamePress}}">{{ctr.itemName}}</ui5-link>
<ui5-link @ui5-press="{{ctr._onItemNamePress}}">{{ctr.itemName}}</ui5-link>
{{/if}}

{{#unless ctr.itemNameClickable}}
Expand Down