Janith Widarshana
Janith Widarshana

Reputation: 3483

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

Upvotes: 15

Views: 17723

Answers (4)

Jorge J Lorenzo
Jorge J Lorenzo

Reputation: 141

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

Upvotes: 9

Kirsten
Kirsten

Reputation: 181

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

Upvotes: 3

Shravani Palnati
Shravani Palnati

Reputation: 79

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

Upvotes: 7

Ajoy Karmakar
Ajoy Karmakar

Reputation: 671

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

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

Upvotes: -2

Related Questions