Skip to content

Commit af1cfbe

Browse files
authored
refactor(components): rename event names to kebab case (#1692)
Rename all components event names that are currently camelCase to kebab-case, but keep the camelCase events firing for backward compatibility for at least one release to allow smooth migrations of the applications. BREAKING_CHANGE: all event names are renamed from camelCase to kebabCase. **Examples**: "selectionChange" becomes "selection-change", "itemClose" becomes "item-close", "afterOpen" becomes "after-open", etc.
1 parent b1e565f commit af1cfbe

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+281
-266
lines changed

docs/Configuration.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ The `noConflict` configuration setting allows certain control over this behavior
6161
The format of this object is as follows:
6262
```json
6363
{
64-
"events": ["selectionChange", "headerClick"]
64+
"events": ["selection-change", "header-click"]
6565
}
6666
```
6767
*Please note that other keys may be added to this object in the future for the purpose of name conflict resolution.*
6868

69-
In the above example, only the `selectionChange` and `headerClick` events will be fired with a prefix.
70-
You can still use them by listening to `ui5-selectionChange` and `ui5-headerClick`, but the names `selectionChange` and `headerClick` will be
69+
In the above example, only the `selection-change` and `header-click` events will be fired with a prefix.
70+
You can still use them by listening to `ui5-selection-change` and `ui5-header-click`, but the names `selection-change` and `header-click` will be
7171
free for use by other UI components and libraries without name collision.
7272

7373
<a name="formatSettings"></a>
@@ -103,7 +103,7 @@ In order to provide configuration settings, include the following ```<script>```
103103
},
104104
"theme": "sap_belize_hcb",
105105
"noConflict": {
106-
"events": ["selectionChange", "headerClick"]
106+
"events": ["selection-change", "header-click"]
107107
}
108108
}
109109
</script>

packages/base/src/UI5Element.js

+15-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import isSlot from "./util/isSlot.js";
1616

1717
const metadata = {
1818
events: {
19-
_propertyChange: {},
19+
"_property-change": {},
2020
},
2121
};
2222

@@ -381,15 +381,15 @@ class UI5Element extends HTMLElement {
381381
this._monitoredChildProps.set(slotName, { observedProps, notObservedProps });
382382
}
383383

384-
child.addEventListener("_propertyChange", this._invalidateParentOnPropertyUpdate);
384+
child.addEventListener("_property-change", this._invalidateParentOnPropertyUpdate);
385385
child._firePropertyChange = true;
386386
}
387387

388388
/**
389389
* @private
390390
*/
391391
_detachChildPropertyUpdated(child) {
392-
child.removeEventListener("_propertyChange", this._invalidateParentOnPropertyUpdate);
392+
child.removeEventListener("_property-change", this._invalidateParentOnPropertyUpdate);
393393
child._firePropertyChange = false;
394394
}
395395

@@ -400,7 +400,7 @@ class UI5Element extends HTMLElement {
400400
this._updateAttribute(name, value);
401401

402402
if (this._firePropertyChange) {
403-
this.dispatchEvent(new CustomEvent("_propertyChange", {
403+
this.dispatchEvent(new CustomEvent("_property-change", {
404404
detail: { name, newValue: value },
405405
composed: false,
406406
bubbles: true,
@@ -596,6 +596,17 @@ class UI5Element extends HTMLElement {
596596
* @returns {boolean} false, if the event was cancelled (preventDefault called), true otherwise
597597
*/
598598
fireEvent(name, data, cancelable) {
599+
const eventResult = this._fireEvent(name, data, cancelable);
600+
const camelCaseEventName = kebabToCamelCase(name);
601+
602+
if (camelCaseEventName !== name) {
603+
return eventResult && this._fireEvent(camelCaseEventName, data, cancelable);
604+
}
605+
606+
return eventResult;
607+
}
608+
609+
_fireEvent(name, data, cancelable) {
599610
let compatEventResult = true; // Initialized to true, because if the event is not fired at all, it should be considered "not-prevented"
600611

601612
const noConflictEvent = new CustomEvent(`ui5-${name}`, {

packages/base/test/pages/ConfigurationScript.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
},
1818
"theme": "sap_belize_hcb",
1919
"noConflict": {
20-
"events": ["selectionChange", "headerClick"]
20+
"events": ["selection-change", "header-click"]
2121
}
2222
}
2323
</script>

packages/base/test/specs/ConfigurationChange.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ describe("Some configuration options can be changed at runtime", () => {
1717
it("Tests that noConflict can be changed", () => {
1818
const res = browser.execute( () => {
1919
const config = window['sap-ui-webcomponents-bundle'].configuration;
20-
config.setNoConflict({events: ["selectionChange"]});
20+
config.setNoConflict({events: ["selection-change"]});
2121
return config.getNoConflict();
2222
});
23-
assert.strictEqual(res.events.includes("selectionChange"), true, "selectionChange was successfully registered as a no conflict event");
23+
assert.strictEqual(res.events.includes("selection-change"), true, "selection-change was successfully registered as a no conflict event");
2424
});
2525
});

packages/base/test/specs/ConfigurationScript.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ describe("Configuration script has effect", () => {
4848
const config = window['sap-ui-webcomponents-bundle'].configuration;
4949
return config.getNoConflict();
5050
});
51-
assert.strictEqual(res.events.includes("selectionChange"), true, "selectionChange was successfully registered as a no conflict event");
51+
assert.strictEqual(res.events.includes("selection-change"), true, "selectionChange was successfully registered as a no conflict event");
5252
});
5353

5454
it("Tests that animationMode is applied", () => {

packages/fiori/src/ShellBar.js

+19-19
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,11 @@ const metadata = {
239239
* Fired, when the notification icon is activated.
240240
*
241241
*
242-
* @event
242+
* @event sap.ui.webcomponents.fiori.ShellBar#notifications-click
243243
* @param {HTMLElement} targetRef dom ref of the activated element
244244
* @public
245245
*/
246-
notificationsClick: {
246+
"notifications-click": {
247247
detail: {
248248
targetRef: { type: HTMLElement },
249249
},
@@ -252,11 +252,11 @@ const metadata = {
252252
/**
253253
* Fired, when the profile slot is present.
254254
*
255-
* @event
255+
* @event sap.ui.webcomponents.fiori.ShellBar#profile-click
256256
* @param {HTMLElement} targetRef dom ref of the activated element
257257
* @public
258258
*/
259-
profileClick: {
259+
"profile-click": {
260260
detail: {
261261
targetRef: { type: HTMLElement },
262262
},
@@ -266,11 +266,11 @@ const metadata = {
266266
* Fired, when the product switch icon is activated.
267267
* <b>Note:</b> You can prevent closing of oveflow popover by calling <code>event.preventDefault()</code>.
268268
*
269-
* @event
269+
* @event sap.ui.webcomponents.fiori.ShellBar#product-switch-click
270270
* @param {HTMLElement} targetRef dom ref of the activated element
271271
* @public
272272
*/
273-
productSwitchClick: {
273+
"product-switch-click": {
274274
detail: {
275275
targetRef: { type: HTMLElement },
276276
},
@@ -279,12 +279,12 @@ const metadata = {
279279
/**
280280
* Fired, when the logo is activated.
281281
*
282-
* @event
282+
* @event sap.ui.webcomponents.fiori.ShellBar#logo-click
283283
* @param {HTMLElement} targetRef dom ref of the activated element
284284
* @since 0.10
285285
* @public
286286
*/
287-
logoClick: {
287+
"logo-click": {
288288
detail: {
289289
targetRef: { type: HTMLElement },
290290
},
@@ -293,12 +293,12 @@ const metadata = {
293293
/**
294294
* Fired, when the co pilot is activated.
295295
*
296-
* @event
296+
* @event sap.ui.webcomponents.fiori.ShellBar#co-pilot-click
297297
* @param {HTMLElement} targetRef dom ref of the activated element
298298
* @since 0.10
299299
* @public
300300
*/
301-
coPilotClick: {
301+
"co-pilot-click": {
302302
detail: {
303303
targetRef: { type: HTMLElement },
304304
},
@@ -308,12 +308,12 @@ const metadata = {
308308
* Fired, when a menu item is activated
309309
* <b>Note:</b> You can prevent closing of oveflow popover by calling <code>event.preventDefault()</code>.
310310
*
311-
* @event
311+
* @event sap.ui.webcomponents.fiori.ShellBar#menu-item-click
312312
* @param {HTMLElement} item dom ref of the activated list item
313313
* @since 0.10
314314
* @public
315315
*/
316-
menuItemClick: {
316+
"menu-item-click": {
317317
detail: {
318318
item: { type: HTMLElement },
319319
},
@@ -431,13 +431,13 @@ class ShellBar extends UI5Element {
431431
}
432432

433433
_menuItemPress(event) {
434-
this.fireEvent("menuItemClick", {
434+
this.fireEvent("menu-item-click", {
435435
item: event.detail.item,
436436
}, true);
437437
}
438438

439439
_logoPress() {
440-
this.fireEvent("logoClick", {
440+
this.fireEvent("logo-click", {
441441
targetRef: this.shadowRoot.querySelector(".ui5-shellbar-logo"),
442442
});
443443
}
@@ -476,7 +476,7 @@ class ShellBar extends UI5Element {
476476
}
477477

478478
_fireCoPilotClick() {
479-
this.fireEvent("coPilotClick", {
479+
this.fireEvent("co-pilot-click", {
480480
targetRef: this.shadowRoot.querySelector(".ui5-shellbar-coPilot"),
481481
});
482482
}
@@ -683,7 +683,7 @@ class ShellBar extends UI5Element {
683683
return item.shadowRoot.querySelector(`#${refItemId}`);
684684
});
685685

686-
const prevented = !shellbarItem.fireEvent("itemClick", { targetRef: event.target }, true);
686+
const prevented = !shellbarItem.fireEvent("item-click", { targetRef: event.target }, true);
687687

688688
this._defaultItemPressPrevented = prevented;
689689
}
@@ -696,21 +696,21 @@ class ShellBar extends UI5Element {
696696
_handleNotificationsPress(event) {
697697
const notificationIconRef = this.shadowRoot.querySelector(".ui5-shellbar-bell-button");
698698

699-
this._defaultItemPressPrevented = !this.fireEvent("notificationsClick", {
699+
this._defaultItemPressPrevented = !this.fireEvent("notifications-click", {
700700
targetRef: notificationIconRef.classList.contains("ui5-shellbar-hidden-button") ? event.target : notificationIconRef,
701701
}, true);
702702
}
703703

704704
_handleProfilePress(event) {
705-
this.fireEvent("profileClick", {
705+
this.fireEvent("profile-click", {
706706
targetRef: this.shadowRoot.querySelector(".ui5-shellbar-image-button"),
707707
});
708708
}
709709

710710
_handleProductSwitchPress(event) {
711711
const buttonRef = this.shadowRoot.querySelector(".ui5-shellbar-button-product-switch");
712712

713-
this._defaultItemPressPrevented = !this.fireEvent("productSwitchClick", {
713+
this._defaultItemPressPrevented = !this.fireEvent("product-switch-click", {
714714
targetRef: buttonRef.classList.contains("ui5-shellbar-hidden-button") ? event.target : buttonRef,
715715
}, true);
716716
}

packages/fiori/src/ShellBarItem.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ const metadata = {
4646
/**
4747
* Fired, when the item is pressed.
4848
*
49-
* @event
49+
* @event sap.ui.webcomponents.fiori.ShellBarItem#item-click
5050
* @param {HTMLElement} targetRef dom ref of the clicked element
5151
* @public
5252
*/
53-
itemClick: {
53+
"item-click": {
5454
detail: {
5555
targetRef: { type: HTMLElement },
5656
},

packages/fiori/src/ShellBarPopover.hbs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<ui5-popover class="ui5-shellbar-menu-popover"
22
placement-type="Bottom"
3-
@ui5-beforeOpen={{_menuPopoverBeforeOpen}}
4-
@ui5-afterClose={{_menuPopoverAfterClose}}
3+
@ui5-before-open={{_menuPopoverBeforeOpen}}
4+
@ui5-after-close={{_menuPopoverAfterClose}}
55
>
6-
<ui5-list separators="None" mode="SingleSelect" @ui5-itemPress={{_menuItemPress}}>
6+
<ui5-list separators="None" mode="SingleSelect" @ui5-item-press={{_menuItemPress}}>
77
{{#each _menuPopoverItems}}
88
{{ this }}
99
{{/each}}
@@ -14,10 +14,10 @@
1414
placement-type="Bottom"
1515
horizontal-align="{{popoverHorizontalAlign}}"
1616
no-arrow
17-
@ui5-beforeOpen={{_overflowPopoverBeforeOpen}}
18-
@ui5-afterClose={{_overflowPopoverAfterClose}}
17+
@ui5-before-open={{_overflowPopoverBeforeOpen}}
18+
@ui5-after-close={{_overflowPopoverAfterClose}}
1919
>
20-
<ui5-list separators="None" @ui5-itemPress="{{_actionList.itemPress}}">
20+
<ui5-list separators="None" @ui5-item-press="{{_actionList.itemPress}}">
2121
{{#each _hiddenIcons}}
2222
<ui5-li
2323
data-ui5-external-action-item-id="{{this.refItemid}}"

packages/fiori/src/UploadCollection.hbs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
<div class="{{classes.content}}">
66
<ui5-list
77
mode="{{mode}}"
8-
@ui5-selectionChange="{{_onSelectionChange}}"
9-
@ui5-itemDelete="{{_onItemDelete}}"
8+
@ui5-selection-change="{{_onSelectionChange}}"
9+
@ui5-item-delete="{{_onItemDelete}}"
1010
>
1111
<slot></slot>
1212
</ui5-list>

packages/fiori/src/UploadCollection.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,11 @@ const metadata = {
129129
* <br><br>
130130
* <b>Note:</b> A Delete button is displayed on each item,
131131
* when the <code>ui5-upload-collection</code> <code>mode</code> property is set to <code>Delete</code>.
132-
* @event
132+
* @event sap.ui.webcomponents.fiori.UploadCollection#file-deleted
133133
* @param {HTMLElement} item The <code>ui5-upload-collection-item</code> which was renamed.
134134
* @public
135135
*/
136-
fileDeleted: {
136+
"file-deleted": {
137137
detail: {
138138
item: { type: HTMLElement },
139139
},
@@ -143,11 +143,11 @@ const metadata = {
143143
* Fired when selection is changed by user interaction
144144
* in <code>SingleSelect</code> and <code>MultiSelect</code> modes.
145145
*
146-
* @event
146+
* @event sap.ui.webcomponents.fiori.UploadCollection#selection-change
147147
* @param {Array} selectedItems An array of the selected items.
148148
* @public
149149
*/
150-
selectionChange: {
150+
"selection-change": {
151151
detail: {
152152
selectedItems: { type: Array },
153153
},
@@ -264,11 +264,11 @@ class UploadCollection extends UI5Element {
264264
}
265265

266266
_onItemDelete(event) {
267-
this.fireEvent("fileDeleted", { item: event.detail.item });
267+
this.fireEvent("file-deleted", { item: event.detail.item });
268268
}
269269

270270
_onSelectionChange(event) {
271-
this.fireEvent("selectionChange", { selectedItems: event.detail.selectedItems });
271+
this.fireEvent("selection-change", { selectedItems: event.detail.selectedItems });
272272
}
273273

274274
get classes() {

packages/fiori/src/UploadCollectionItem.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const metadata = {
5858
},
5959

6060
/**
61-
* If set to <code>true</code> the file name will be clickable and it will fire <code>fileNameClick</code> event upon click.
61+
* If set to <code>true</code> the file name will be clickable and it will fire <code>file-name-click</code> event upon click.
6262
*
6363
* @type {boolean}
6464
* @defaultvalue false
@@ -171,10 +171,10 @@ const metadata = {
171171
* <br><br>
172172
* <b>Note:</b> This event is only available when <code>fileNameClickable</code> property is <code>true</code>.
173173
*
174-
* @event
174+
* @event sap.ui.webcomponents.fiori.UploadCollectionItem#file-name-click
175175
* @public
176176
*/
177-
fileNameClick: { },
177+
"file-name-click": { },
178178

179179
/**
180180
* Fired when the <code>fileName</code> property gets changed.
@@ -322,7 +322,7 @@ class UploadCollectionItem extends ListItem {
322322
}
323323

324324
_onFileNameClick(event) {
325-
this.fireEvent("fileNameClick");
325+
this.fireEvent("file-name-click");
326326
}
327327

328328
_onRetry(event) {

0 commit comments

Comments
 (0)