Actually, it looks like all you need to do is add myToggle.blur()
:
const clickToggleById = (key: ValidKeysEnum): void => {
const myToggle = document.querySelector(`#test-${key} ion-toggle`);
if (myToggle instanceof HTMLElement) {
// Only click the toggle if it is not disabled.
if ('disabled' in myToggle) {
if (!myToggle.disabled) {
myToggle.click();
myToggle.blur();
}
} else {
myToggle.click();
myToggle.blur();
}
}
};