Select to view content in your preferred language

Cannot open calcite-alert again after closing it

666
2
Jump to solution
07-24-2023 10:52 AM
ForrestLin
Frequent Contributor

I cannot open calcite-alert again after closing it by re-setting open = true.

How to re-use calcite-alert?

0 Kudos
2 Solutions

Accepted Solutions
KittyHurley
Esri Contributor

@ForrestLin Can you share a Codepen with the behavior mentioned? Here's an example of toggling an Alert with a Button click event, which shows how to toggle the Alert's "open" attribute.

View solution in original post

0 Kudos
ForrestLin
Frequent Contributor

Hi Kitty, Thanks for your help. The issue is fixed by calling toggleAttribute("open") in Angular.

Here is my Alert Angular Component:

alert.component.html
---------------------------------
 
<calcite-alert [icon]="alert.icon" [kind]="alert. Kind"
  [label]="alert. Label" #alertNode>
  <div slot="title">{{alert.title}}</div>
  <div slot="message">{{alert. Message}}</div>
</calcite-alert>
 
------------------------------------------------------------------------------------------------
 
alert.component.ts
----------------------------
 
@Component({
  selector: 'app-alert',
  templateUrl: './alert.component.html',
  styleUrls: ['./alert.component.css']
})
export class AlertComponent implements OnInit, OnDestroy {
  @ViewChild('alertNode', { static: true })
  private _alertEl!: ElementRef;
 
  alert: Alert = {
    ........................
  };
 
  public openAlert() {
    if (!this._alertEl.nativeElement.open) {
      this._alertEl.nativeElement.toggleAttribute("open");
    }
  }
}
 
 Forrest

View solution in original post

0 Kudos
2 Replies
KittyHurley
Esri Contributor

@ForrestLin Can you share a Codepen with the behavior mentioned? Here's an example of toggling an Alert with a Button click event, which shows how to toggle the Alert's "open" attribute.

0 Kudos
ForrestLin
Frequent Contributor

Hi Kitty, Thanks for your help. The issue is fixed by calling toggleAttribute("open") in Angular.

Here is my Alert Angular Component:

alert.component.html
---------------------------------
 
<calcite-alert [icon]="alert.icon" [kind]="alert. Kind"
  [label]="alert. Label" #alertNode>
  <div slot="title">{{alert.title}}</div>
  <div slot="message">{{alert. Message}}</div>
</calcite-alert>
 
------------------------------------------------------------------------------------------------
 
alert.component.ts
----------------------------
 
@Component({
  selector: 'app-alert',
  templateUrl: './alert.component.html',
  styleUrls: ['./alert.component.css']
})
export class AlertComponent implements OnInit, OnDestroy {
  @ViewChild('alertNode', { static: true })
  private _alertEl!: ElementRef;
 
  alert: Alert = {
    ........................
  };
 
  public openAlert() {
    if (!this._alertEl.nativeElement.open) {
      this._alertEl.nativeElement.toggleAttribute("open");
    }
  }
}
 
 Forrest
0 Kudos