-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix (image): Allow closing insert via url dialog window by enter key #17633
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The approach for this fix went into a good direction, to have a form in place so enter
could be handled 👍 However, the changes you applied affects DialogView
component globally (see review comments) which is not what we want IMHO.
The right approach would be to modify to ImageInsertViaUrlUI
to have the form element rendered into the dialog and then proper submit handling. There are other plugins (like MediaEmbed
) which already have this so you may take a look how it's done there.
@@ -260,7 +260,7 @@ export default class DialogView extends /* #__PURE__ */ DraggableViewMixin( View | |||
}, | |||
children: [ | |||
{ | |||
tag: 'div', | |||
tag: 'form', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DialogView
is a "generic" component reused by CKEditor 5 in multiple places by multiple plugins. This change would affect all of the dialogs so this is not the right place for such change if we only want to adjust the behavior of a specific plugins dialog.
@@ -186,6 +191,7 @@ describe( 'ImageInsertViaUrlUI', () => { | |||
|
|||
testSubmit( 'accept button', () => acceptButton.fire( 'execute' ) ); | |||
|
|||
// Can not be checked by simulating enter click because of unit test limitations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a good approach to describe "not so obvious" code, however this could use some more details to be clear. You could describe that we fire form submit
event to simulate what browser does on enter
press instead of trying to trigger enter
key event on a button directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First thing, always make sure that CI is green when passing a PR for a review. Here, there is one job failing (cc is not 100% after recent changes).
Second thing, as for:
The approach for this fix went into a good direction, to have a form in place so
enter
could be handled 👍 However, the changes you applied affectsDialogView
component globally (see review comments) which is not what we want IMHO.The right approach would be to modify to
ImageInsertViaUrlUI
to have the form element rendered into the dialog and then proper submit handling. There are other plugins (likeMediaEmbed
) which already have this so you may take a look how it's done there.
Well, you solved it by adding a flag, but it's unnecessary and makes the generic dialog more complex. As each plugin has a full control over it's views and can render anything there, there is no reason for lifting this logic higher in components hierarchy.
As suggested before, we already have plugins doing this. You may take a look on MediaEmbed plugin and its UI (here is the view definition) and see how "Image insert via URL" view can be adjusted (here).
/** | ||
* Browsers handle clicking Enter for form submitting by its own but unit test can not, it is known limitation. | ||
* We fire a form submit event to simulate the behavior that occurs when pressing Enter in the browser. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** | |
* Browsers handle clicking Enter for form submitting by its own but unit test can not, it is known limitation. | |
* We fire a form submit event to simulate the behavior that occurs when pressing Enter in the browser. | |
*/ | |
/** | |
* Browsers handle pressing Enter on forms natively by submitting it. We fire a form submit event to simulate that behavior. | |
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it could be a bit shorter as above. And a "nitpick", enter
is pressed not clicked (usually at least 😄).
Just wanted to add something here. The funny thing is that we already have a test which checks "enter submit" behavior, and it happily passes. This is because, the tests simulates "submit via enter" by sending a submit event on a top dialog view element (which is a ckeditor5/packages/ckeditor5-image/tests/imageinsert/imageinsertviaurlui.js Lines 189 to 193 in fd1d41e
ckeditor5/packages/ckeditor5-image/src/imageinsert/ui/imageinserturlview.ts Lines 71 to 72 in fd1d41e
And then we have ckeditor5/packages/ckeditor5-image/src/imageinsert/imageinsertviaurlui.ts Lines 175 to 178 in fd1d41e
However, browser natively will not trigger the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Suggested merge commit message (convention)
Fix (image): Insert image via url dialog can be closed by "enter" button when input is focused. Closes #16902.
I tried to add better unit tests for this case but submitting form by "enter" button works different in browser than in unit test environment. I left comment to prevent confusion why unit test has no "enter" click.