Skip to content

Build your personal knowledge base with Trilium Notes

feat(widgets/toggle): disable transitions on first render

Elian Doran9f2ed2f9d47c
diff --git a/apps/client/src/widgets/react/FormToggle.css b/apps/client/src/widgets/react/FormToggle.css
index 9418391430..bfe5bdc614 100644
--- a/apps/client/src/widgets/react/FormToggle.css
+++ b/apps/client/src/widgets/react/FormToggle.css
@@ -24,6 +24,14 @@
border-radius: 24px;
background-color: var(--switch-off-track-background);
transition: background 200ms ease-in;
+
+ &.disable-transitions {
+ transition: none !important;
+
+ &:after {
+ transition: none !important;
+ }
+ }
}
.switch-widget .switch-button.on {
@@ -103,4 +111,4 @@ body[dir=rtl] .switch-widget .switch-button.on:after {
.switch-widget .switch-help-button:hover {
color: var(--main-text-color);
-}
\ No newline at end of file
+}
diff --git a/apps/client/src/widgets/react/FormToggle.tsx b/apps/client/src/widgets/react/FormToggle.tsx
index ba7499f367..39be5cd70e 100644
--- a/apps/client/src/widgets/react/FormToggle.tsx
+++ b/apps/client/src/widgets/react/FormToggle.tsx
@@ -1,5 +1,7 @@
+import clsx from "clsx";
import "./FormToggle.css";
import HelpButton from "./HelpButton";
+import { useEffect, useState } from "preact/hooks";
interface FormToggleProps {
currentValue: boolean | null;
@@ -13,13 +15,22 @@ interface FormToggleProps {
}
export default function FormToggle({ currentValue, helpPage, switchOnName, switchOnTooltip, switchOffName, switchOffTooltip, onChange, disabled }: FormToggleProps) {
+ const [ disableTransition, setDisableTransition ] = useState(true);
+
+ useEffect(() => {
+ const timeout = setTimeout(() => {
+ setDisableTransition(false);
+ }, 100);
+ return () => clearTimeout(timeout);
+ }, []);
+
return (
<div className="switch-widget">
<span className="switch-name">{ currentValue ? switchOffName : switchOnName }</span>
<label>
<div
- className={`switch-button ${currentValue ? "on" : ""} ${disabled ? "disabled" : ""}`}
+ className={clsx("switch-button", { "on": currentValue, disabled, "disable-transitions": disableTransition })}
title={currentValue ? switchOffTooltip : switchOnTooltip }
>
<input