#61919 closed defect (bug) (fixed)
Ctrl + Enter with focus on "Edit your profile" within the comment form tries to submit form
Reported by: | greentreefrog | Owned by: | joedolson |
---|---|---|---|
Milestone: | 6.7 | Priority: | normal |
Severity: | normal | Version: | 5.3 |
Component: | Comments | Keywords: | has-patch commit |
Focuses: | accessibility, javascript | Cc: |
Description (last modified by )
This also happens on the "Log out?" link in the comment form.
To reproduce:
- Log into a WordPress site (so you will be able to see the link in question).
- Open a post that allows comments.
- Tab to the "Edit your profile" link. Technically, this link is inside the comment form. (A user should not be expected to know this.)
- Hold down the Ctrl key and click the Enter key.
As a user, I would expect the profile page to open in a new tab. That is not what happens. Instead, WordPress tries to submit the form and does not open a new tab. If there is no text in the Comment field, WordPress shows this error page:
Error: Please type your comment text. « Back
If there is already text in the comment field, WordPress simply submits the comment. I do not get taken to the profile page.
I have tried this with the Jace, Twenty Twenty-Four and Twenty Twenty-three themes. I have tried it on 4 different sites. On one site I disabled all plugins and tried again. I always had this same result.
This probably relates to the following issue, where a key handler was added to trap Ctrl + Enter in the Comment form: [45790]
One solution might be to move these links outside the form.
Alternatively, ChatGPT suggests I could use the following JavaScript code; I include it in case it helps someone fix it quicker. Of course, modify it to fit the context:
document.addEventListener('keydown', function(event) { if (event.ctrlKey && event.key === 'Enter') { event.preventDefault(); let activeElement = document.activeElement; if (activeElement.tagName.toLowerCase() === 'a') { window.open(activeElement.href, '_blank'); } } });
Thanks for looking into this!
Margaret
Change History (6)
#1
@
6 weeks ago
- Description modified (diff)
- Milestone changed from Awaiting Review to Future Release
- Version changed from 6.6.1 to 5.3
This ticket was mentioned in PR #7238 on WordPress/wordpress-develop by @narenin.
6 weeks ago
#2
- Keywords has-patch added; needs-patch removed
Trac ticket: https://core.trac.wordpress.org/ticket/61919
#4
@
5 weeks ago
- Keywords commit added; needs-testing removed
- Owner set to joedolson
- Status changed from new to accepted
Tested:
Before patch: Ctrl/Cmd + Enter on links within form simultaneously open the link in a new tab and submit the form. (In my testing, this did not override the behavior, but actually did both.)
After patch: Ctrl/Cmd + Enter on links within the form opens the link in a new tab without submitting the form.
In both cases, Ctrl/Cmd + Enter submits the form as expected when on an input field.
Marking for commit.
@joedolson commented on PR #7238:
5 weeks ago
#6
In r58981.
Hi and thanks for the report!
I can confirm that the issue occurs with WordPress 5.3 but not 5.2, which makes [45790] the likely cause.
With a quick test, I was able to adjust the conditional statement to skip the submit feature if the active element is a link:
Someone else may know a better way to write that, too.