A bit of code to manage focus state in a form with multiple fields.
Add onBlur event to the Form which will be firen whenever focus leaves any field in the Form. To preserve active state the new target might be tested whether it's inside the same form or not with the following line.
function deactivateForm(e) {
const form = document.getElementById('myForm');
if (!form.contains(e.relatedTarget)) setIsActive(false);
}