diff --git a/src/components/ebay-accordion/accordion.stories.ts b/src/components/ebay-accordion/accordion.stories.ts
index 9568d5e30..b87b1e04a 100644
--- a/src/components/ebay-accordion/accordion.stories.ts
+++ b/src/components/ebay-accordion/accordion.stories.ts
@@ -53,8 +53,8 @@ export default {
},
},
},
- item: {
- name: "@item",
+ details: {
+ name: "@details",
description:
"Represents an element to be used as part of the group. Allowed attributes are `open`, `as`, `text` and `renderBody`",
table: {
@@ -71,6 +71,16 @@ export default {
},
},
},
+ onClick: {
+ action: "on-click",
+ description: "Triggered on click of details",
+ table: {
+ category: "Events",
+ defaultValue: {
+ summary: "{ originalEvent }",
+ },
+ },
+ },
},
};
diff --git a/src/components/ebay-accordion/component-browser.ts b/src/components/ebay-accordion/component-browser.ts
index 128a0452a..6fb3f53c1 100644
--- a/src/components/ebay-accordion/component-browser.ts
+++ b/src/components/ebay-accordion/component-browser.ts
@@ -6,10 +6,11 @@ export interface AccordionInput extends Omit, `on${string}`> {
size?: "regular" | "large";
"auto-collapse"?: AttrBoolean;
"a11y-role-description"?: AttrString;
- item?: Marko.AttrTag<
+ details?: Marko.AttrTag<
Omit
>;
"on-toggle"?: (event: { originalEvent: Event; open: boolean }) => void;
+ "on-click"?: (event: { originalEvent: MouseEvent }) => void;
}
export interface Input extends WithNormalizedProps {}
@@ -17,16 +18,26 @@ class Accordion extends Marko.Component {
handleToggle(event: { originalEvent: Event; open: boolean }) {
const { autoCollapse } = this.input;
- if(autoCollapse && event.open) {
- const accordion = this.getEl("accordion-root") as HTMLUListElement;
- const detailsElements = accordion.querySelectorAll("details");
+ const accordion = this.getEl("accordion-root") as HTMLUListElement;
+ const detailsElements = Array.from(accordion.querySelectorAll("details"));
+ const index = detailsElements.indexOf(
+ event.originalEvent.target as HTMLDetailsElement,
+ );
+
+ if (autoCollapse && event.open) {
detailsElements.forEach((details: HTMLDetailsElement) => {
// Close the element by setting its open attribute to false
if (details !== event.originalEvent.target) {
details.open = false;
- }
- });
+ }
+ });
}
+
+ this.emit("toggle", {
+ originalEvent: event.originalEvent,
+ open: (event.originalEvent.target as HTMLDetailsElement).open,
+ index,
+ });
}
}
diff --git a/src/components/ebay-accordion/examples/autoCollapsed.marko b/src/components/ebay-accordion/examples/autoCollapsed.marko
index 4e4b4b41a..6c3863ae9 100644
--- a/src/components/ebay-accordion/examples/autoCollapsed.marko
+++ b/src/components/ebay-accordion/examples/autoCollapsed.marko
@@ -1,11 +1,14 @@
- <@item text="Item 1">
+ <@details>
+ <@summary>Item 1@summary>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
- @item>
- <@item text="Item 2">
+ @details>
+ <@details>
+ <@summary>Item 2@summary>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
- @item>
- <@item text="Item 3">
+ @details>
+ <@details>
+ <@summary>Item 3@summary>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
- @item>
+ @details>
diff --git a/src/components/ebay-accordion/examples/default.marko b/src/components/ebay-accordion/examples/default.marko
index 7e3e3425e..d93307d13 100644
--- a/src/components/ebay-accordion/examples/default.marko
+++ b/src/components/ebay-accordion/examples/default.marko
@@ -1,11 +1,14 @@
- <@item text="Item 1">
+ <@details>
+ <@summary>Item 1@summary>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
- @item>
- <@item text="Item 2">
+ @details>
+ <@details>
+ <@summary>Item 2@summary>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
- @item>
- <@item text="Item 3">
+ @details>
+ <@details>
+ <@summary>Item 3@summary>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
- @item>
+ @details>
diff --git a/src/components/ebay-accordion/examples/large.marko b/src/components/ebay-accordion/examples/large.marko
index 6ad85223e..e417152cb 100644
--- a/src/components/ebay-accordion/examples/large.marko
+++ b/src/components/ebay-accordion/examples/large.marko
@@ -1,11 +1,14 @@
- <@item text="Item 1">
+ <@details>
+ <@summary>Item 1@summary>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
- @item>
- <@item text="Item 2">
+ @details>
+ <@details>
+ <@summary>Item 2@summary>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
- @item>
- <@item text="Item 3">
+ @details>
+ <@details>
+ <@summary>Item 3@summary>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
- @item>
+ @details>
diff --git a/src/components/ebay-accordion/examples/opened.marko b/src/components/ebay-accordion/examples/opened.marko
index 974d1ce6f..d8b9cadf6 100644
--- a/src/components/ebay-accordion/examples/opened.marko
+++ b/src/components/ebay-accordion/examples/opened.marko
@@ -1,11 +1,14 @@
- <@item text="Item 1" open>
+ <@details open>
+ <@summary>Item 1@summary>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
- @item>
- <@item text="Item 2">
+ @details>
+ <@details>
+ <@summary>Item 2@summary>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
- @item>
- <@item text="Item 3">
+ @details>
+ <@details>
+ <@summary>Item 3@summary>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
- @item>
+ @details>
diff --git a/src/components/ebay-accordion/index.marko b/src/components/ebay-accordion/index.marko
index 46a63eb6c..0e8fe9b87 100644
--- a/src/components/ebay-accordion/index.marko
+++ b/src/components/ebay-accordion/index.marko
@@ -5,7 +5,7 @@ static function noop() {}
$ const {
class: inputClass,
size,
- item: items = [],
+ details: items = [],
autoCollapse,
a11yRoleDescription,
...htmlInput
@@ -25,6 +25,7 @@ $ (input as any).toJSON = noop;
...item
layout="accordion"
on-toggle("handleToggle")
+ on-click("emit", "click")
>
<${item.renderBody} />
diff --git a/src/components/ebay-accordion/marko-tag.json b/src/components/ebay-accordion/marko-tag.json
index daa4dc664..d2a2fea37 100644
--- a/src/components/ebay-accordion/marko-tag.json
+++ b/src/components/ebay-accordion/marko-tag.json
@@ -11,14 +11,13 @@
"@as": "string",
"@auto-collapse": "boolean",
"@a11y-role-description": "string",
- "@item []": {
+ "@details []": {
"attribute-groups": ["html-attributes"],
"@*": {
"targetProperty": null,
"type": "expression"
},
- "@html-attributes": "expression",
- "@text": "string"
+ "@html-attributes": "expression"
},
"description": "[view documentation](https://ebay.github.io/ebayui-core/?path=/story/navigation-disclosure-ebay-accordion)"
}
diff --git a/src/components/ebay-accordion/test/__snapshots__/test.server.js.snap b/src/components/ebay-accordion/test/__snapshots__/test.server.js.snap
index 42929f653..562ee588d 100644
--- a/src/components/ebay-accordion/test/__snapshots__/test.server.js.snap
+++ b/src/components/ebay-accordion/test/__snapshots__/test.server.js.snap
@@ -28,11 +28,11 @@ exports[`accordion > renders accordion with auto-collapse true 1`] = `
[36m
`;
@@ -62,44 +26,8 @@ exports[`details > passes through additional html attributes 2`] = `
style="color:red"
type="number"
>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
`;
@@ -126,11 +54,11 @@ exports[`details > renders as div version 1`] = `
[36m[39m
[36m[39m
[36m renders as div version 1`] = `
[36m[39m
[36m[39m
[36m
[39m
@@ -230,11 +158,11 @@ exports[`details > renders center version 1`] = `
[36m[39m
[36m[39m
[36m renders center version 1`] = `
[36m[39m
[36m[39m
[36m
[39m
[0mbody content[0m
[36m
[39m
@@ -282,11 +210,11 @@ exports[`details > renders in open state 1`] = `
[36m[39m
[36m[39m
[36m renders in open state 1`] = `
[36m[39m
[36m[39m
[36m
[39m
[0mbody content[0m
[36m
[39m
@@ -334,11 +262,11 @@ exports[`details > renders small version 1`] = `
[36m[39m
[36m[39m
[36m renders small version 1`] = `
[36m[39m
[36m[39m
[36m
[39m
[0mbody content[0m
[36m
[39m
diff --git a/src/components/ebay-details/test/mock/index.js b/src/components/ebay-details/test/mock/index.js
index a9a077d1b..2de91616d 100644
--- a/src/components/ebay-details/test/mock/index.js
+++ b/src/components/ebay-details/test/mock/index.js
@@ -2,7 +2,9 @@
import { createRenderBody } from "../../../../common/test-utils/shared";
export const Default_Details = {
- text: "open",
+ summary: {
+ renderBody: createRenderBody("open"),
+ },
renderBody: createRenderBody("body content"),
};
diff --git a/src/components/ebay-details/test/test.browser.js b/src/components/ebay-details/test/test.browser.js
index d20960ee0..7237f31cb 100644
--- a/src/components/ebay-details/test/test.browser.js
+++ b/src/components/ebay-details/test/test.browser.js
@@ -26,7 +26,9 @@ describe("given the details is in the default state", () => {
it("should render with open false", () => {
expect(
- component.getByText(input.text).closest("details").open,
+ component
+ .getByText(input.summary.renderBody.text)
+ .closest("details").open,
).to.equal(false);
});
});
@@ -40,14 +42,16 @@ describe("given the details is in the open state", () => {
it("should render with open false", () => {
expect(
- component.getByText(input.text).closest("details").open,
+ component
+ .getByText(input.summary.renderBody.text)
+ .closest("details").open,
).to.equal(true);
});
});
describe("given the details is in the default state and click is triggered", () => {
const input = mock.Default_Details;
- const detailsText = input.text;
+ const detailsText = input.summary.renderBody.text;
beforeEach(async () => {
component = await render(template, input);
@@ -67,7 +71,7 @@ describe("given the details is in the default state and click is triggered", ()
describe("given the details is in the open state and click is triggered", () => {
const input = mock.Open_Details;
- const detailsText = input.text;
+ const detailsText = input.summary.renderBody.text;
beforeEach(async () => {
component = await render(template, input);