Skip to content

Commit

Permalink
: Ensure that the active tab exists.
Browse files Browse the repository at this point in the history
  • Loading branch information
George-Payne committed Oct 3, 2024
1 parent fb12b85 commit 4d8bb49
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/fifty-jokes-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@eventstore-ui/components': patch
---

`es-tabs`: Ensure that the active tab exists.
7 changes: 7 additions & 0 deletions packages/components/src/components/es-tabs/es-tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export class EsTabs {

componentWillLoad() {
this.setUpActiveParam(this.activeParam);
this.updateActiveIfNoMatchesTabs(this.tabs);
}

disconnectedCallback() {
Expand Down Expand Up @@ -90,6 +91,12 @@ export class EsTabs {
this.tabChange.emit(active);
}

@Watch('tabs')
updateActiveIfNoMatchesTabs(tabs: Tab[]) {
if (tabs.find(({ id }) => id === this.active)) return;
this.active = this.tabs[0].id;
}

renderTab = ({ title, id, badge }: Tab, i: number) => (
<>
{i !== 0 && !!this.interTabIcon && (
Expand Down

0 comments on commit 4d8bb49

Please sign in to comment.