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', () => {