Skip to content

Commit

Permalink
Merge pull request #15137 from ckeditor/ck/15091-focus-goes-nowhere-a…
Browse files Browse the repository at this point in the history
…fter-inserting-something-from-the-ckbox

Other (ckbox): Should focus the editor after choosing an asset or closing CKBox. Closes #15091.
  • Loading branch information
arkflpc authored Oct 6, 2023
2 parents 93f01bb + aba284f commit c6d1028
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/ckeditor5-ckbox/src/ckboxcommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ export default class CKBoxCommand extends Command {

this._wrapper!.remove();
this._wrapper = null;

editor.editing.view.focus();
} );

// Handle choosing the assets.
Expand Down Expand Up @@ -227,6 +229,8 @@ export default class CKBoxCommand extends Command {
}
}
} );

editor.editing.view.focus();
} );

// Clean up after the editor is destroyed.
Expand Down
26 changes: 26 additions & 0 deletions packages/ckeditor5-ckbox/tests/ckboxcommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,24 @@ describe( 'CKBoxCommand', () => {
expect( spy.callCount ).to.equal( 1 );
expect( command._wrapper ).to.equal( null );
} );

it( 'should focus view after closing the CKBox dialog', () => {
const focusSpy = testUtils.sinon.spy( editor.editing.view, 'focus' );

const openSpy = sinon.spy();
const closeSpy = sinon.spy();

command.on( 'ckbox:open', openSpy );
command.execute();

command.on( 'ckbox:close', closeSpy );
onClose();

expect( openSpy.callCount ).to.equal( 1 );
expect( closeSpy.callCount ).to.equal( 1 );

sinon.assert.calledOnce( focusSpy );
} );
} );

describe( 'choosing assets ("ckbox:choose")', () => {
Expand Down Expand Up @@ -1013,6 +1031,14 @@ describe( 'CKBoxCommand', () => {
expect( command._chosenAssets.size ).to.equal( 0 );
expect( command._wrapper ).to.equal( null );
} );

it( 'should focus view after assets were chosen', () => {
const focusSpy = testUtils.sinon.spy( editor.editing.view, 'focus' );

onChoose( [ ...assets.images, ...assets.links ] );

sinon.assert.calledOnce( focusSpy );
} );
} );
} );
} );
Expand Down

0 comments on commit c6d1028

Please sign in to comment.