Fix visual bug in latest HA (#203)

This commit is contained in:
Christiaan Goossens
2026-02-06 12:29:04 +01:00
committed by GitHub
parent d6b8f6bbb1
commit 0f0679d46d

View File

@@ -19,6 +19,7 @@ function showCode() {
}
let ssoButton = null
let codeButton = null
let codeMessage = null
let codeToggle = null
let codeToggleText = null
@@ -28,11 +29,19 @@ function update() {
const loginHeader = document.querySelector(".card-content > ha-auth-flow > form > h1")
const authForm = document.querySelector("ha-auth-form")
const codeField = document.querySelector(".mdc-text-field__input[name=code]")
const loginButton = document.querySelector("ha-button:not(.sso)")
const haButtons = document.querySelectorAll("ha-button:not(.sso)")
const errorAlert = document.querySelector("ha-auth-form ha-alert[alert-type=error]")
const loginOptionList = document.querySelector("ha-pick-auth-provider")?.shadowRoot?.querySelector("ha-list")
const forgotPasswordLink = document.querySelector(".forgot-password")
// Iterate over haButtons to find one with text "Login with code"
let loginButton = null
haButtons.forEach(button => {
if (button.textContent.trim() === "Log in") {
loginButton = button
}
})
// ====
// Code input
if (codeField) {
@@ -68,7 +77,6 @@ function update() {
}
authForm.style.display = showCode() ? "" : "none"
loginButton.style.display = showCode() ? "" : "none"
}
if (authForm && !codeMessage) {
@@ -81,7 +89,23 @@ function update() {
codeMessage.style.display = showCode() ? "" : "none"
}
safeSetTextContent(loginButton, codeField ? "Log in with code" : "Log in")
if (showCode() && loginButton !== null && !codeButton) {
codeButton = document.createElement("ha-button")
codeButton.id = "code_button"
codeButton.classList.add("code")
codeButton.innerText = "Log in with code"
codeButton.setAttribute("raised", "")
codeButton.style.marginRight = "1em"
// Copy the onclick handler the loginButton
codeButton.addEventListener("click", () => {
loginButton.click()
})
loginButton.parentElement.prepend(codeButton)
} else if (!showCode() && loginButton !== null &&codeButton) {
codeButton.remove()
codeButton = null
}
// ====
// Toggle button
@@ -125,7 +149,7 @@ function update() {
const shouldShowSSOButton = !showCode() && !!codeField
const isOurScreen = showCode() || shouldShowSSOButton
if (loginButton && !ssoButton) {
if (loginButton !== null && !ssoButton) {
ssoButton = document.createElement("ha-button")
ssoButton.id = "sso_button"
ssoButton.classList.add("sso")
@@ -150,10 +174,16 @@ function update() {
if (isOurScreen) {
// Hide the header on our screens
loginHeader.style.display = "none"
if (loginButton !== null) {
loginButton.style.display = "none"
}
forgotPasswordLink.style.display = "none"
} else {
// Show the header on the login screen
loginHeader.style.display = ""
if (loginButton !== null) {
loginButton.style.display = ""
}
forgotPasswordLink.style.display = ""
}
}