Fix form submit on bold inline tool click (#2775)

This commit is contained in:
Tatiana Fomina 2024-07-10 23:13:37 +03:00 committed by GitHub
commit b6674367a5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 40 additions and 1 deletions

View file

@ -3,6 +3,7 @@
### 2.30.2
- `Fix` The onChange callback won't be fired when editor is initialized in the Read-Only mode
- `Fix` Prevent form submit on inline tool click
### 2.30.1

View file

@ -147,7 +147,9 @@ export class PopoverItemDefault extends PopoverItem {
*/
private make(params: PopoverItemDefaultParams, renderParams?: PopoverItemRenderParamsMap[PopoverItemType.Default]): HTMLElement {
const tag = renderParams?.wrapperTag || 'div';
const el = Dom.make(tag, css.container);
const el = Dom.make(tag, css.container, {
type: tag === 'button' ? 'button' : undefined,
});
if (params.name) {
el.dataset.itemName = params.name;

View file

@ -76,6 +76,42 @@ describe('Inline Toolbar', () => {
});
});
it('should not submit form nesting editor when inline tool clicked', () => {
cy.createEditor({
data: {
blocks: [
{
type: 'paragraph',
data: {
text: 'Some text',
},
},
],
},
});
const onSubmit = cy.stub();
cy.document().then(doc => {
const form = doc.createElement('form');
form.onsubmit = onSubmit;
doc.body.appendChild(form);
/* Move editor to form */
form.appendChild(doc.getElementById('editorjs'));
cy.get('[data-cy=editorjs]')
.find('.ce-paragraph')
.selectText('Some text');
cy.get('[data-item-name=bold]')
.click();
expect(onSubmit).to.be.not.called;
});
});
describe('Conversion toolbar', () => {
it('should restore caret after converting of a block', () => {
cy.createEditor({