ionic-framework icon indicating copy to clipboard operation
ionic-framework copied to clipboard

feat: ion-alert add a slot for full customization

Open fanckush opened this issue 1 year ago • 7 comments
trafficstars

Prerequisites

Describe the Feature Request

I would like to replicate this loading alert that you get when sharing a video from the photos app. IMG_9462

however currently, there are no slots to alert so this is not possible

Describe the Use Case

one use case is to add icons like in this closed issue https://github.com/ionic-team/ionic-framework/issues/7874

Describe Preferred Solution

using a default slot is probably the most flexible solution, then the user can have whatever they want inside such as Ion-icon and animated stuff

Describe Alternatives

No response

Related Code

No response

Additional Information

No response

fanckush avatar Aug 08 '24 15:08 fanckush

HTML can be passed to the message prop of the ion-alert. From the docs: innerHTMLTemplatesEnabled must be set to true in the Ionic config before custom HTML can be used. And for security reasons, your custom HTML are sanitized as well.

see: https://ionicframework.com/docs/api/alert#message

<ion-button id="present-alert">Click Me</ion-button>

<ion-alert
  trigger="present-alert"
  header="A Short Title Is Best"
  sub-header="A Sub Header Is Optional"
  message="`
    <div class='my-class'>
      <h2> I am a boy </h2>
      <img src='https://unsplash.it/600/400?image=501' />
    </div>
  `"
  :buttons="alertButtons"
>
</ion-alert>

crispy-acorn-7wwxxqvg4grfxj7g-8080 app github dev_cus-test(iPhone 14 Pro Max) (1)

I probably don't understand what you plan to achieve, but to achieve full flexibility where you can have whatever you "want inside such as Ion-icon and animated stuff", why don't you consider using a modal?

dev-charles15531 avatar Aug 16 '24 10:08 dev-charles15531

thanks! I didn't know you could pass HTML like that. It's not ideal of course because it's static and harder to interact with.

my goal it pretty much get that same loading animation as in the screenshot I posted

fanckush avatar Aug 16 '24 10:08 fanckush

You can achieve that with a modal.

dev-charles15531 avatar Aug 16 '24 10:08 dev-charles15531

yes, i'm aware of that, and that's what I ended up doing, but it was painful from the sizing, to the animation.

fanckush avatar Aug 16 '24 14:08 fanckush

With the recent feature addition of inline overlays in Ionic Framework, we should consider adding new slots to the element so developers can better customize the contents of the alert to their needs.

There will still limitations that the alerts are designed to match iOS/MD design guidelines, but the contents inside could be customized with an API that doesn't require passing HTML as a string.

If you do pass HTML as a string, make sure to pass it through a DOM sanitizer or similar to protect your application from javascript injection.

sean-perkins avatar Aug 19 '24 19:08 sean-perkins

+1 for adding a slot

oliveryasuna avatar Feb 14 '25 03:02 oliveryasuna

I found this feature request. Indeed, a way to add an icon or an image would be appreciate. At my side, it was more on top on the alert (see below).

Image

TiBz0u avatar Jun 03 '25 09:06 TiBz0u