Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set Tab if value on Initialisation #22

Merged
merged 1 commit into from
Dec 11, 2023

Conversation

Dioltas95
Copy link
Contributor

  • Updated Component to set the correct tab if a cron value is set on Initialisation

Copy link
Owner

@haavardj haavardj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks ok.

@haavardj haavardj merged commit 80c613e into haavardj:master Dec 11, 2023
@@ -213,21 +213,27 @@ export class CronGenComponent implements OnInit, OnDestroy, ControlValueAccessor
break;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although the tabIndex is set to 0 initially, this might require setting the tabIndex back to 0 when the cron expression changes back to a minutely value.
If the component is not reloaded, then I believe it would get stuck on another tab if the value were to become minutely.

The usage of selecting the tab by its index I believe would break when hiding tabs.
*ngif removes tabs from the dom, so the index for it is not actually used up when rendering the tabs.

i.e.
The Minutes Tab is in position 0 if it were rendered.
If options.hideMinutesTab is true, then index 0 would actually be the Hourly Tab, so the switch statement would select the wrong index when setting the expression.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How to select a tab by its label:

@ViewChild('tabGroup') tabGroup! : MatTabGroup;

ngAfterViewInit() {
  this.setTabByLabel();
}

setTabByLabel() {
  let tab = this.tabGroup._allTabs.toArray().find((tabItem: MatTab) => tabItem.textLabel === this.tabName);
  if (tab && !tab.disabled) {
    this.tabGroup.selectedIndex = this.tabGroup._allTabs.toArray().indexOf(tab);
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants