From 7b784bc5bc9fe06246a585557e002f512ef70928 Mon Sep 17 00:00:00 2001 From: Steeve Vandecappelle Date: Tue, 19 Mar 2019 11:31:15 +0100 Subject: [PATCH] feat(oui-collapsible): add handler on toggle open-close event --- packages/oui-collapsible/README.md | 9 +++++++++ .../src/collapsible.component.js | 3 ++- .../src/collapsible.controller.js | 1 + packages/oui-collapsible/src/index.spec.js | 18 ++++++++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/packages/oui-collapsible/README.md b/packages/oui-collapsible/README.md index 1641c506..534f9bc1 100644 --- a/packages/oui-collapsible/README.md +++ b/packages/oui-collapsible/README.md @@ -20,6 +20,14 @@ ``` +### Event handler + +```html:preview + + Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis semper ligula nec fringilla tempor. In rhoncus ullamcorper feugiat. Phasellus vel ipsum vitae neque varius luctus. Proin id iaculis arcu. Fusce justo arcu, egestas vel nulla nec, dictum cursus lacus. Aenean elementum vel odio quis rutrum. In quis tellus in neque vulputate rhoncus vitae ut justo. Ut dignissim varius est in consequat. Donec nisi mauris, pellentesque condimentum congue in, blandit ut arcu. In et elit ipsum. + +``` + ## API ### oui-collapsible @@ -29,3 +37,4 @@ | `heading` | string | @ | no | n/a | n/a | text of the heading | `aria-label` | string | @? | yes | n/a | n/a | accessibility label | `expanded` | boolean | { const contentEl = bodyEl.querySelector(".custom-content"); expect(contentEl).toBeTruthy(); }); + + it("should call ontoggle when defined into attributes", () => { + const onToggle = jasmine.createSpy("onToggle"); + const element = TestUtils.compileTemplate(` + `, { + onToggle + }); + + const headerEl = angular.element(getHeaderElement(element)); + + // Expand + headerEl.triggerHandler("click"); + expect(onToggle).toHaveBeenCalledWith(true); + + // Collapse + headerEl.triggerHandler("click"); + expect(onToggle).toHaveBeenCalledWith(false); + }); }); });