Fix visual bug in latest HA (#203)
This commit is contained in:
committed by
GitHub
parent
d6b8f6bbb1
commit
0f0679d46d
@@ -19,6 +19,7 @@ function showCode() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let ssoButton = null
|
let ssoButton = null
|
||||||
|
let codeButton = null
|
||||||
let codeMessage = null
|
let codeMessage = null
|
||||||
let codeToggle = null
|
let codeToggle = null
|
||||||
let codeToggleText = null
|
let codeToggleText = null
|
||||||
@@ -28,11 +29,19 @@ function update() {
|
|||||||
const loginHeader = document.querySelector(".card-content > ha-auth-flow > form > h1")
|
const loginHeader = document.querySelector(".card-content > ha-auth-flow > form > h1")
|
||||||
const authForm = document.querySelector("ha-auth-form")
|
const authForm = document.querySelector("ha-auth-form")
|
||||||
const codeField = document.querySelector(".mdc-text-field__input[name=code]")
|
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 errorAlert = document.querySelector("ha-auth-form ha-alert[alert-type=error]")
|
||||||
const loginOptionList = document.querySelector("ha-pick-auth-provider")?.shadowRoot?.querySelector("ha-list")
|
const loginOptionList = document.querySelector("ha-pick-auth-provider")?.shadowRoot?.querySelector("ha-list")
|
||||||
const forgotPasswordLink = document.querySelector(".forgot-password")
|
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
|
// Code input
|
||||||
if (codeField) {
|
if (codeField) {
|
||||||
@@ -68,7 +77,6 @@ function update() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
authForm.style.display = showCode() ? "" : "none"
|
authForm.style.display = showCode() ? "" : "none"
|
||||||
loginButton.style.display = showCode() ? "" : "none"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (authForm && !codeMessage) {
|
if (authForm && !codeMessage) {
|
||||||
@@ -80,8 +88,24 @@ function update() {
|
|||||||
if (codeMessage) {
|
if (codeMessage) {
|
||||||
codeMessage.style.display = showCode() ? "" : "none"
|
codeMessage.style.display = showCode() ? "" : "none"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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"
|
||||||
|
|
||||||
safeSetTextContent(loginButton, codeField ? "Log in with code" : "Log in")
|
// 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
|
// Toggle button
|
||||||
@@ -125,7 +149,7 @@ function update() {
|
|||||||
const shouldShowSSOButton = !showCode() && !!codeField
|
const shouldShowSSOButton = !showCode() && !!codeField
|
||||||
const isOurScreen = showCode() || shouldShowSSOButton
|
const isOurScreen = showCode() || shouldShowSSOButton
|
||||||
|
|
||||||
if (loginButton && !ssoButton) {
|
if (loginButton !== null && !ssoButton) {
|
||||||
ssoButton = document.createElement("ha-button")
|
ssoButton = document.createElement("ha-button")
|
||||||
ssoButton.id = "sso_button"
|
ssoButton.id = "sso_button"
|
||||||
ssoButton.classList.add("sso")
|
ssoButton.classList.add("sso")
|
||||||
@@ -150,10 +174,16 @@ function update() {
|
|||||||
if (isOurScreen) {
|
if (isOurScreen) {
|
||||||
// Hide the header on our screens
|
// Hide the header on our screens
|
||||||
loginHeader.style.display = "none"
|
loginHeader.style.display = "none"
|
||||||
|
if (loginButton !== null) {
|
||||||
|
loginButton.style.display = "none"
|
||||||
|
}
|
||||||
forgotPasswordLink.style.display = "none"
|
forgotPasswordLink.style.display = "none"
|
||||||
} else {
|
} else {
|
||||||
// Show the header on the login screen
|
// Show the header on the login screen
|
||||||
loginHeader.style.display = ""
|
loginHeader.style.display = ""
|
||||||
|
if (loginButton !== null) {
|
||||||
|
loginButton.style.display = ""
|
||||||
|
}
|
||||||
forgotPasswordLink.style.display = ""
|
forgotPasswordLink.style.display = ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user