How to remove small caret from ion-select in ionic4

前端 未结 10 1204
春和景丽
春和景丽 2021-01-17 22:21

I want to remove the inbuilt grey small caret from ion-select, and use my custom caret(arrow) instead.

Code:

ion-select {
  color: grey         


        
相关标签:
10条回答
  • 2021-01-17 23:16

    I've created this directive which you can add to your ion-select to make it look just like other ion elements with placeholder (without arrow).

    Usage:

    <ion-select placeholder="Choose" appNoArrow>...
    
    0 讨论(0)
  • 2021-01-17 23:18

    If you want to quite the icon of ion-select-option only add mode="ios" on

    0 讨论(0)
  • 2021-01-17 23:22

    If there are several ion-select items, here is a sample.

    TS Code :

    ionViewDidEnter() {
        // ion-select customizing
        const ionSelects = document.querySelectorAll('ion-select');
        let img = null;
        ionSelects.forEach((ionSelect) => {
          const selectIconInner = ionSelect.shadowRoot.querySelector('.select-icon').querySelector('.select-icon-inner');
          if(selectIconInner){
            selectIconInner.attributes.removeNamedItem("class");
            img = document.createElement("img");
            img.src = "./new-arrow-down-image.svg";
            img.style.width = "12px";
            img.style.paddingTop = "3px";
            img.style.paddingLeft = "4px";
            img.style.color = "black";
            img.style.opacity = "0.5";
            selectIconInner.appendChild(img);
          }
        });
    }
    
    0 讨论(0)
  • 2021-01-17 23:23

    I don't know how to fix, faced same problem, but it seems to be issue with DOM Shadow

    If you will find anything, let to know as well please, thanks.

    Update: Found some answer

    UPDATE #2

    I created directive in order to have access to Shadow DOM and it's able to add styles into isolated DOM.

    HTML:

     <ion-select appStyle>
    

    Directive(need to find better implementation):

        constructor(private el: ElementRef) {
    
        setTimeout(() => {
            this.el.nativeElement.shadowRoot.querySelector('.select-icon-inner').setAttribute('style', 'display: none !important');
        }, 3000);
    }
    
    0 讨论(0)
提交回复
热议问题