Fix error when trying to scroll to an invalid field

This commit is contained in:
Andrew Kingston 2023-12-08 16:52:34 +00:00
parent 9da641f848
commit ee452f75fe
1 changed files with 7 additions and 3 deletions

View File

@ -423,10 +423,14 @@
} }
const fieldId = field.fieldState.fieldId const fieldId = field.fieldState.fieldId
const fieldElement = document.getElementById(fieldId) const fieldElement = document.getElementById(fieldId)
fieldElement.focus({ preventScroll: true }) if (fieldElement) {
fieldElement.focus({ preventScroll: true })
}
const label = document.querySelector(`label[for="${fieldId}"]`) const label = document.querySelector(`label[for="${fieldId}"]`)
label.style.scrollMargin = "100px" if (label) {
label.scrollIntoView({ behavior: "smooth", block: "nearest" }) label.style.scrollMargin = "100px"
label.scrollIntoView({ behavior: "smooth", block: "nearest" })
}
} }
// Action context to pass to children // Action context to pass to children