added view transition for smoother theme toggle

This commit is contained in:
sairaj mote 2023-09-26 16:42:59 +05:30
parent 30bf7add5f
commit 0f7e96328f

View File

@ -102,8 +102,15 @@ class ThemeToggle extends HTMLElement {
}
toggleState() {
this.toggleAttribute('checked');
this.fireEvent();
if (!document.startViewTransition) {
this.toggleAttribute('checked');
this.fireEvent();
return;
}
document.startViewTransition(() => {
this.toggleAttribute('checked');
this.fireEvent();
});
}
handleKeyDown(e) {
if (e.key === ' ') {