问题
I want to remove the inbuilt grey small caret from ion-select
, and use my
custom caret(arrow) instead.
Code:
ion-select {
color: grey;
background:url("/assets/resources/img/ArrowDownConfig.svg") no-repeat 92% center !important;
}
But my css code is unable to precedence over the ionic(inbuilt).
You can see there are two arrows in the image, one is inbuilt and another is custom. I want to remove inbuilt(ionic) one.
回答1:
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);
}
回答2:
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);
}
});
}
回答3:
If you want just remove the carets, you can do this:
// ...other page methods
ionViewDidEnter() {
const ionSelects = document.querySelectorAll('ion-select');
ionSelects.forEach((sel) => {
sel.shadowRoot.querySelectorAll('.select-icon-inner')
.forEach((elem) => {
elem.setAttribute('style', 'display: none;');
});
});
}
Based on @Sangminem response
In my case, I'm using slot="end"
with an ion-icon
to place the icon:
<ion-item lines="inset">
<ion-label position="floating">Label</ion-label>
<ion-select>
<ion-select-option value="1">Option 1</ion-select-option>
<ion-select-option value="2">Option 2</ion-select-option>
<ion-select-option value="2">Option 3</ion-select-option>
</ion-select>
<ion-icon color="danger" slot="end" name="arrow-dropdown-circle" align-self-center></ion-icon>
</ion-item>
回答4:
.select-icon-inner {
border-top: transparent!important;}
I think this is only possible with ioni3. If you want to solve only css in ionic4, you need to know the exact class name of select-icon in ionic4
回答5:
To modify the icon , you can try something like this :.select-icon-inner {
border-top: transparent!important;
}
来源:https://stackoverflow.com/questions/55300777/how-to-remove-small-caret-from-ion-select-in-ionic4