ionic-team / ionic-team/ionic-framework

feat: allow custom spinners for `ion-spinner`/`ion-loading`

Open
#23,912 6 comments 3 reactions 0 assignees View on GitHub
package: core type: feature request
Dominant language
TypeScript
Stars
52.7k
Forks
13.3k
Avg merge
1d 15h
Merged PRs (30d)
51

Description

### Prequisites

- [X] I have read the [Contributing Guidelines](https://github.com/ionic-team/ionic-framework/blob/main/.github/CONTRIBUTING.md#creating-an-issue).
- [X] I agree to follow the [Code of Conduct](https://ionicframework.com/code-of-conduct).
- [X] I have searched for [existing issues](https://github.com/ionic-team/ionic-framework/issues) that already include this feature request, without success.

### Describe the Feature Request

Allow an HTML element (such as one created with `createElement()`) to be given to the `ion-spinner`. This functionality should be able to come through to `ion-loading`, as it uses an `ion-spinner` under the hood.

### Describe the Use Case

Sometimes I want a spinner that "just works", but want it to be slightly more "on brand" than a stock style.
I created a Vue component that holds an animated SVG (for easy reuse), but have no way to use it with Ionic.
Note: a Vue component gets compiled to standard HTML elements, so the root element of the Vue component can be passed to the `ion-spinner`.

Maybe using a custom spinner design violates someone's interface design guidelines/rules? (looking at you Apple)

### Describe Preferred Solution

Allow an element to be given when creating a spinner using the spinner controller.

Not sure which way would be best.
Maybe change the `spinner` property/param to allow `HTMLElement` as well or something?
For the element version of `ion-spinner`, it could use a named slot: `slot="spinner"`?

### Describe Alternatives

1. Use a custom spinner instead of `ion-spinner`. This can actually work in many cases, but not when I want to use `ion-loading`.
2. Set the spinner style to `none` and target the background of the spinner with CSS. e.g. `background: url(#my-spinner-svg)`
Someone on the Ionic forum mentioned doing this as a workaround. I can find it again if needed.
This unfortunately is more complex and only allows for a single SVG to be set.

### Related Code

_No response_

### Additional Information

As to implementing, I looked at Ionic's source, and I think this could get hairy. If it would be too complex, please say so and feel free to drop the request :).

Contributor guide

Open the contributing guide

Research direction

Start by reading the ion-spinner and ion-loading implementations and the spinner controller API to understand how spinner content currently flows between them. Check whether the proposed HTMLElement input can be supported in both element and controller usage, and define done as custom spinner elements rendering correctly through ion-spinner and ion-loading.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.