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,11 +423,15 @@
}
const fieldId = field.fieldState.fieldId
const fieldElement = document.getElementById(fieldId)
if (fieldElement) {
fieldElement.focus({ preventScroll: true })
}
const label = document.querySelector(`label[for="${fieldId}"]`)
if (label) {
label.style.scrollMargin = "100px"
label.scrollIntoView({ behavior: "smooth", block: "nearest" })
}
}
// Action context to pass to children
const actions = [