From 302b63ce784707214f414c9086472864a0446f6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Clarissa-kamily-brisa=E2=80=9D?= <“larissa.kamily@grupobrisanet.com.br”> Date: Fri, 22 Sep 2023 10:07:10 -0300 Subject: [PATCH] feat: adding close when options is selected behavior (#834) --- projects/ion/src/lib/sidebar/sidebar.component.html | 4 ++-- projects/ion/src/lib/sidebar/sidebar.component.ts | 5 ++++- projects/ion/src/lib/sidebar/sidebar.spec.ts | 7 +++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/projects/ion/src/lib/sidebar/sidebar.component.html b/projects/ion/src/lib/sidebar/sidebar.component.html index 0c0c4a64e..7d3eb0a30 100644 --- a/projects/ion/src/lib/sidebar/sidebar.component.html +++ b/projects/ion/src/lib/sidebar/sidebar.component.html @@ -16,7 +16,7 @@ iconType="left3" size="lg" type="ghost" - (ionOnClick)="toggleVisibility()" + (ionOnClick)="toggleSidebarVisibility()" >
@@ -53,6 +53,6 @@ iconType="sandwich" size="lg" type="ghost" - (ionOnClick)="toggleVisibility()" + (ionOnClick)="toggleSidebarVisibility()" > diff --git a/projects/ion/src/lib/sidebar/sidebar.component.ts b/projects/ion/src/lib/sidebar/sidebar.component.ts index eff85832f..615dd962b 100644 --- a/projects/ion/src/lib/sidebar/sidebar.component.ts +++ b/projects/ion/src/lib/sidebar/sidebar.component.ts @@ -27,7 +27,7 @@ export class IonSidebarComponent { } }; - public toggleVisibility(): void { + public toggleSidebarVisibility(): void { this.closed = !this.closed; if (!this.closed) { setTimeout(() => { @@ -41,14 +41,17 @@ export class IonSidebarComponent { public itemSelected(itemIndex: number): void { selectItemByIndex(this.items, itemIndex); + this.toggleSidebarVisibility(); } public itemOnGroupSelected(groupIndex: number): void { unselectAllItems(this.items, groupIndex); + this.toggleSidebarVisibility(); } public groupSelected(groupIndex: number): void { unselectAllItems(this.items); callItemAction(this.items, groupIndex); + this.toggleSidebarVisibility(); } } diff --git a/projects/ion/src/lib/sidebar/sidebar.spec.ts b/projects/ion/src/lib/sidebar/sidebar.spec.ts index 912791556..a7321d3b8 100644 --- a/projects/ion/src/lib/sidebar/sidebar.spec.ts +++ b/projects/ion/src/lib/sidebar/sidebar.spec.ts @@ -209,6 +209,13 @@ describe('Sidebar', () => { userEvent.click(groupName); expect(actionMock).toHaveBeenCalledTimes(1); }); + describe('Selecting option', () => { + it('should close sidebar when options is selected', () => { + userEvent.click(item1); + expect(item1).toHaveClass(selectedItemClass); + expect(getByTestId('sidebar')).not.toHaveClass('ion-sidebar--opened'); + }); + }); }); }); describe('Clicking outside it', () => {