8
votes

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

3
do you want to set the blue one instead the grey? - לבני מלכה
Yes. I need to have blue one. It is my custom icon - Janith Widarshana
This is a bit tricky one currently. I would suggest creating a directive for this: stackoverflow.com/a/55303341/6294072 Unfortunately doesn't seem to be a better option currently. - AJT82

3 Answers

5
votes

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; 
}
3
votes

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;
}
0
votes

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

ion-select {
  min-width: 100vw;
}