Skip to content

Commit

Permalink
feat: adding close when options is selected behavior (#834)
Browse files Browse the repository at this point in the history
  • Loading branch information
“larissa-kamily-brisa” committed Sep 22, 2023
1 parent 38d8fb8 commit 302b63c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions projects/ion/src/lib/sidebar/sidebar.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
iconType="left3"
size="lg"
type="ghost"
(ionOnClick)="toggleVisibility()"
(ionOnClick)="toggleSidebarVisibility()"
></ion-button>
</header>
<section class="ion-sidebar__items">
Expand Down Expand Up @@ -53,6 +53,6 @@
iconType="sandwich"
size="lg"
type="ghost"
(ionOnClick)="toggleVisibility()"
(ionOnClick)="toggleSidebarVisibility()"
></ion-button>
</span>
5 changes: 4 additions & 1 deletion projects/ion/src/lib/sidebar/sidebar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class IonSidebarComponent {
}
};

public toggleVisibility(): void {
public toggleSidebarVisibility(): void {
this.closed = !this.closed;
if (!this.closed) {
setTimeout(() => {
Expand All @@ -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();
}
}
7 changes: 7 additions & 0 deletions projects/ion/src/lib/sidebar/sidebar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 302b63c

Please sign in to comment.