diff --git a/themes/src/main/resources/theme/keycloak.v2/login/template.ftl b/themes/src/main/resources/theme/keycloak.v2/login/template.ftl index 818c890979..0398a9541c 100644 --- a/themes/src/main/resources/theme/keycloak.v2/login/template.ftl +++ b/themes/src/main/resources/theme/keycloak.v2/login/template.ftl @@ -48,6 +48,21 @@ checkCookiesAndSetTimer( "${url.ssoLoginInOtherTabsUrl?no_esc}" ); + + const DARK_MODE_CLASS = "pf-v5-theme-dark"; + const mediaQuery =window.matchMedia("(prefers-color-scheme: dark)"); + updateDarkMode(mediaQuery.matches); + mediaQuery.addEventListener("change", (event) => + updateDarkMode(event.matches), + ); + function updateDarkMode(isEnabled) { + const { classList } = document.documentElement; + if (isEnabled) { + classList.add(DARK_MODE_CLASS); + } else { + classList.remove(DARK_MODE_CLASS); + } + }