13

I need to set a custom icon to ion-select. Following is my code and output

<ion-item class="input-container" align-items-center no-padding>
  <ion-label position="floating" no-margin no-padding>I am a</ion-label>
  <ion-select formControlName="role" mode="ios" okText="Okay" cancelText="Cancel">
    <ion-select-option value="Admin">Admin</ion-select-option>
    <ion-select-option value="Customer">Customer</ion-select-option>
  </ion-select>
  <ion-icon color="primary" name="arrow-down" mode="ios" slot="end"></ion-icon>
</ion-item>

enter image description here

Is there any other way of set custom icon or can anyone suggest a way tohow to remove select-icon-inner

Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
Janith Widarshana
  • 3,213
  • 9
  • 51
  • 73

4 Answers4

7

You can override the content of the icon part. This worked for me, just go with:

ion-select::part(icon) {
  content: url('your-icon-path/your-icon.svg');
}

StackBlitz working example

Javier Lorenzo
  • 121
  • 1
  • 6
  • Works well! This should be the accepted answer. It seems like the most correct way to solve the problem. – Zac Dec 08 '21 at 15:41
6

In ionic v4 a workaround is hiding the icon through .scss file.

ion-select::part(icon) {
  display: none !important;
}

ion-select::part(text) {
  background-image: url(<ImageUrl>);
  background-position: right;
  background-repeat: no-repeat; 
}
yanckst
  • 438
  • 4
  • 17
2

This worked for me in i5:

ion-select::part(icon) {
  opacity: 1;
  margin-left: 1em;
  color: transparent;
  background: url('assets/icons/light-mode/expand-down.svg') no-repeat center;
}
Kirsten
  • 171
  • 1
  • 3
  • 13
-2

It's not a proper solution but still, it can fix this problem. Apply this style in .scss file -

ion-select {
  min-width: 100vw;
}
Ajoy Karmakar
  • 671
  • 7
  • 14