Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #240 from ckeditor/t/238
Browse files Browse the repository at this point in the history
Fix: The dropdown menu should not open using the keyboard when disabled. Closes #238.
  • Loading branch information
szymonkups authored Jun 1, 2017
2 parents abbb68f + 6ab7614 commit fc524b8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/dropdown/dropdownview.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ export default class DropdownView extends View {

// Open the dropdown panel using the arrow down key, just like with return or space.
this.keystrokes.set( 'arrowdown', ( data, cancel ) => {
if ( !this.isOpen ) {
// Don't open if the dropdown is disabled or already open.
if ( this.isEnabled && !this.isOpen ) {
this.isOpen = true;
cancel();
}
Expand Down
18 changes: 18 additions & 0 deletions tests/dropdown/dropdownview.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ describe( 'DropdownView', () => {
stopPropagation: sinon.spy()
};

view.isEnabled = true;

view.isOpen = true;
view.keystrokes.press( keyEvtData );
sinon.assert.notCalled( keyEvtData.preventDefault );
Expand All @@ -140,6 +142,22 @@ describe( 'DropdownView', () => {
expect( view.isOpen ).to.be.true;
} );

it( 'so "arrowdown" won\'t open the #panelView when #isEnabled is false', () => {
const keyEvtData = {
keyCode: keyCodes.arrowdown,
preventDefault: sinon.spy(),
stopPropagation: sinon.spy()
};

view.isEnabled = false;
view.isOpen = false;

view.keystrokes.press( keyEvtData );
sinon.assert.notCalled( keyEvtData.preventDefault );
sinon.assert.notCalled( keyEvtData.stopPropagation );
expect( view.isOpen ).to.be.false;
} );

it( 'so "arrowright" is blocked', () => {
const keyEvtData = {
keyCode: keyCodes.arrowright,
Expand Down

0 comments on commit fc524b8

Please sign in to comment.