Skip to content

Commit 2608100

Browse files
authored
refactor(ui5-panel): rename the expand event to toggle (#216)
Fire toggle event on expand/collapse instead of expand. BREAKING CHANGE: the expand event is removed, use the toggle event instead.
1 parent c1f98a3 commit 2608100

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

packages/main/src/Panel.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ const metadata = {
140140
* @event
141141
* @public
142142
*/
143-
expand: {},
143+
toggle: {},
144144
},
145145
};
146146

@@ -163,8 +163,11 @@ const metadata = {
163163
* A panel consists of a title bar with a header text or custom header.
164164
* <br>
165165
* The content area can contain an arbitrary set of controls.
166-
* The header can contain a title with text and icons, buttons, and a
167-
* collapse icon, which allows to show/hide the content area.
166+
* The header is clickable and can be used to toggle between the expanded and collapsed state.
167+
* It includes an icon which rotates depending on the state.
168+
* <br>
169+
* The custom header can be set through the <code>header</code> slot and it may contain arbitraray content, such as: title, buttons or any other HTML elements.
170+
* <br><b>Note:</b> the custom header is not clickable out of the box, but in this case the icon is interactive and allows to show/hide the content area.
168171
*
169172
* <h3>Responsive Behavior</h3>
170173
* <ul>
@@ -279,14 +282,10 @@ class Panel extends WebComponent {
279282
Promise.all(animations).then(_ => {
280283
this._animationRunning = false;
281284
this._contentExpanded = !this.collapsed;
282-
this._fireExpandEvent();
285+
this.fireEvent("toggle");
283286
});
284287
}
285288

286-
_fireExpandEvent() {
287-
this.fireEvent("expand", {});
288-
}
289-
290289
_headerOnTarget(target) {
291290
return target.classList.contains("sapMPanelWrappingDiv");
292291
}

packages/main/test/sap/ui/webcomponents/main/pages/Panel.html

+3-4
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,12 @@
2727

2828
<script>
2929
document.addEventListener("DOMContentLoaded", function () {
30-
panel1.addEventListener("expand", function (event) {
30+
panel1.addEventListener("toggle", function (event) {
3131
console.log(event);
32-
event.target.headerText = event.detail.expand ? "Click to collapse!" : "Click to expand!";
32+
event.target.headerText = event.target.collapsed ? "Click to expand!" : "Click to collapse!";
3333
field1.value = parseInt(field1.value) + 1;
3434
});
35-
panel2.addEventListener("expand", function (event) {
36-
event.target.headerText = event.detail.expand ? "Click to collapse!" : "Click to expand!";
35+
panel2.addEventListener("toggle", function (event) {
3736
field2.value = parseInt(field2.value) + 1;
3837
});
3938

packages/main/test/specs/Panel.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const assert = require("assert");
33
describe("Panel general interaction", () => {
44
browser.url("http://localhost:8080/test-resources/sap/ui/webcomponents/main/pages/Panel.html");
55

6-
it("tests expand event upon header click", () => {
6+
it("tests toggle event upon header click", () => {
77
const header = browser.findElementDeep("#panel1 >>> .sapMPanelWrappingDiv");
88
const field = browser.$("#field1");
99

@@ -19,7 +19,7 @@ describe("Panel general interaction", () => {
1919
assert.strictEqual(field.getProperty("value"), "3", "Press should be called 3 times");
2020
});
2121

22-
it("tests expand event upon icon click with custom header", () => {
22+
it("tests toggle event upon icon click with custom header", () => {
2323
const icon = browser.findElementDeep("#panel2 >>> ui5-icon");
2424
const field = browser.$("#field2");
2525

0 commit comments

Comments
 (0)