Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic 4 ion-select set custom icon for select-icon

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

like image 512
Janith Widarshana Avatar asked May 01 '19 07:05

Janith Widarshana


3 Answers

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

like image 135
Javier Lorenzo Avatar answered Oct 28 '22 06:10

Javier Lorenzo


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; 
}
like image 42
Shravani Palnati Avatar answered Oct 28 '22 05:10

Shravani Palnati


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;
}
like image 2
Kirsten Avatar answered Oct 28 '22 07:10

Kirsten