Tweet |
Introduction
The Winter 23 release of Salesforce provided something that, in my view, we've been desperately seeking since the original (Aura) Lightning Components broke cover in 2014 - modal alerts provided by the platform. I'd imagine there are hundreds if not thousands of modal implementations out there, mostly based on the Lightning Design System styling, and all being maintained separately. Some in Aura, some in LWC, but all duplicating effort.
I feel like we have cross-origin alert blocking in Chrome to thank for this - if that wasn't breaking things then I can't see Salesforce would suddenly have prioritised it after all these years - but it doesn't matter how we got them, we have them!
Show Me The Code!
The alerts are refreshingly simple to use too - simply import LightningAlert:
1 | import LightningAlert from 'lightning/alert' ; |
and then execute the LightningAlert.open() function:
1 2 3 4 5 6 7 8 | async showAlert() { await LightningAlert.open({ message: 'Here is the alert that will be shown to the user' , theme: 'warning' , label: 'Alerted' , variant: 'header' }); } |
and the user sees the alert
No comments:
Post a Comment