9

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

Kai - Kazuya Ito
  • 6,454
  • 5
  • 44
  • 50
Janith Widarshana
  • 2,795
  • 8
  • 45
  • 64

4 Answers4

5

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
  • 101
  • 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
4

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
  • 378
  • 3
  • 15
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
  • 12
-1

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
  • 663
  • 7
  • 14