Ionic 4: How to overwrite style in Shadow elements that are not controlled by css variables?

后端 未结 1 1185
野的像风
野的像风 2021-01-26 03:58

I have to style a small app built with Ionic 4

The HTML is:

相关标签:
1条回答
  • 2021-01-26 04:41

    ion-searchbar as some other elements expose a method to access underlying "input" element - getInputElement. That should allow you to add styles if needed. Below is how you can do that with Ionic 4.11.5:

    Template remains the same, but in ts file you could do:

    import { IonSearchbar } from '@ionic/angular';
    ///
    export class MySearchPage {
    
        @ViewChild(IonSearchbar, { static: false }) searchbar: IonSearchbar;
        ///
        ngAfterViewInit() {
            this.searchbar.getInputElement().then((searchbarInputElement)=>{
          searchbarInputElement.style.boxShadow = "none";
            // in case you need to style its parent as well:
            //searchbarInputElement.parentElement.style.boxShadow = "none";
        })
      };
    
    }
    

    Let me know if this helps.

    0 讨论(0)
提交回复
热议问题