简体   繁体   中英

How to change the input field color in Ionic 5 when focused?

I want to change the color of the input field, when it's focused. It's only that grey, when it gets focused by the following function and only as long as I don't type or click on the field.

export function autofocus() {
    let blanks = document.querySelectorAll(".blank")
    let textfield = document.getElementById("textfield")

    if (blanks.length > 0) {
        document.querySelectorAll(".blank")[0].setFocus()
    }
    else if (textfield) {
        document.getElementById("textfield").setFocus()
    }
}

在此处输入图片说明

The class that is responsible for it, is:

:host(.ion-focused) .item-native::after {
    background: var(--background-focused);
    opacity: var(--background-focused-opacity);
}

Unfortunately it's part of the Shadow DOM. Does anybody know, how to fix that? The opacity should be zero.

Solved it.

ion-item.ion-focused::part(native)::after {
    opacity: 0!important;
  }

Resources that helped me:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM