Onsubmit for confirm dialog doesn't register enter key

I am trying to allow users to acknowledge a confirmation dialog by simply hitting return or enter on the keyboard. In the example below the onsubmit handler doesn’t seem to be registered by the user hitting the enter key. In other dialogs it works when I have a text field and the text area has been clicked into.
Any thoughts on what I can do to make the “Yes” call to action returned with the enter key?

const confirm = async (title, confirmMessage) => {
    const theDialog = document.createElement("dialog");
    const theForm = document.createElement("form");
    const theTitle = document.createElement(`sp-heading`);
    const theBody = document.createElement(`sp-heading`);
    const theFooter = document.createElement("footer");
    const theYesButton = document.createElement("sp-button");
    const theNoButton = document.createElement("sp-button");
    theYesButton.style.margin = "5px";
    theNoButton.style.margin = "5px";
    theTitle.style.fontSize = "20px"
    theBody.style.fontSize = "16px";

    theBody.textContent = confirmMessage;
    theTitle.textContent = title;
    theYesButton.textContent = "Yes";
    theYesButton.setAttribute("variant", "cta");
    theNoButton.textContent = "No";
    theNoButton.setAttribute("variant", "secondary");

    theYesButton.onclick = () => {
        theDialog.close(true);
    };
    theNoButton.onclick = () => {
        theDialog.close(false);
    };

    theForm.onsubmit = () => {
        theDialog.close(true);
    };

    theFooter.appendChild(theYesButton);
    theFooter.appendChild(theNoButton);
    theForm.appendChild(theTitle);
    theForm.appendChild(theBody);
    theForm.appendChild(theFooter);
    theDialog.appendChild(theForm);
    document.body.appendChild(theDialog);

    const r = await theDialog.uxpShowModal({
        title: "Please Confirm",
        resize: "none", // "both", "horizontal", "vertical",
        size: {
            width: 320,
            height: 200,
        },
    });
    theDialog.remove();
    return r;

};