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

Commit fc524b8

Browse files
authored
Merge pull request #240 from ckeditor/t/238
Fix: The dropdown menu should not open using the keyboard when disabled. Closes #238.
2 parents abbb68f + 6ab7614 commit fc524b8

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/dropdown/dropdownview.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ export default class DropdownView extends View {
148148

149149
// Open the dropdown panel using the arrow down key, just like with return or space.
150150
this.keystrokes.set( 'arrowdown', ( data, cancel ) => {
151-
if ( !this.isOpen ) {
151+
// Don't open if the dropdown is disabled or already open.
152+
if ( this.isEnabled && !this.isOpen ) {
152153
this.isOpen = true;
153154
cancel();
154155
}

tests/dropdown/dropdownview.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ describe( 'DropdownView', () => {
127127
stopPropagation: sinon.spy()
128128
};
129129

130+
view.isEnabled = true;
131+
130132
view.isOpen = true;
131133
view.keystrokes.press( keyEvtData );
132134
sinon.assert.notCalled( keyEvtData.preventDefault );
@@ -140,6 +142,22 @@ describe( 'DropdownView', () => {
140142
expect( view.isOpen ).to.be.true;
141143
} );
142144

145+
it( 'so "arrowdown" won\'t open the #panelView when #isEnabled is false', () => {
146+
const keyEvtData = {
147+
keyCode: keyCodes.arrowdown,
148+
preventDefault: sinon.spy(),
149+
stopPropagation: sinon.spy()
150+
};
151+
152+
view.isEnabled = false;
153+
view.isOpen = false;
154+
155+
view.keystrokes.press( keyEvtData );
156+
sinon.assert.notCalled( keyEvtData.preventDefault );
157+
sinon.assert.notCalled( keyEvtData.stopPropagation );
158+
expect( view.isOpen ).to.be.false;
159+
} );
160+
143161
it( 'so "arrowright" is blocked', () => {
144162
const keyEvtData = {
145163
keyCode: keyCodes.arrowright,

0 commit comments

Comments
 (0)