diff --git a/test/unit/ui/picker.js b/test/unit/ui/picker.js index 4283f4c3a9..b45d0ba12a 100644 --- a/test/unit/ui/picker.js +++ b/test/unit/ui/picker.js @@ -1,10 +1,6 @@ +import Keyboard from '../../../modules/keyboard'; import Picker from '../../../ui/picker'; -const KEYCODES = { - ENTER: 13, - ESCAPE: 27, -} - function createKeydownEvent(keyCode) { let event; if (typeof Event === 'function') { @@ -64,7 +60,7 @@ describe('Picker', function() { const pickerLabel = this.pickerSelector.querySelector('.ql-picker-label'); // Select picker via enter key - const e = createKeydownEvent(KEYCODES.ENTER); + const e = createKeydownEvent(Keyboard.keys.ENTER); pickerLabel.dispatchEvent(e); expect(pickerLabel.getAttribute('aria-expanded')).toEqual('true'); @@ -110,7 +106,7 @@ describe('Picker', function() { const pickerItem = this.pickerSelector.querySelector('.ql-picker-item'); // Select picker item via enter key - const e = createKeydownEvent(KEYCODES.ENTER); + const e = createKeydownEvent(Keyboard.keys.ENTER); pickerItem.dispatchEvent(e); expect(pickerLabel.getAttribute('aria-expanded')).toEqual('false'); @@ -131,7 +127,7 @@ describe('Picker', function() { pickerLabel.click(); // Escape out of the picker - const e = createKeydownEvent(KEYCODES.ESCAPE); + const e = createKeydownEvent(Keyboard.keys.ESCAPE); pickerLabel.dispatchEvent(e); expect(pickerLabel.getAttribute('aria-expanded')).toEqual('false'); diff --git a/ui/picker.js b/ui/picker.js index 74a400d132..8b8b1b3007 100644 --- a/ui/picker.js +++ b/ui/picker.js @@ -1,10 +1,6 @@ +import Keyboard from '../modules/keyboard'; import DropdownIcon from '../assets/icons/dropdown.svg'; -const KEYCODES = { - ENTER: 13, - ESCAPE: 27, -} - let OPTIONS_ID = 0; function toggleAriaAttribute(element, attribute) { @@ -25,12 +21,12 @@ class Picker { this.label.addEventListener('keydown', (event) => { switch(event.keyCode) { // Allows the "Enter" key to open the picker - case KEYCODES.ENTER: + case Keyboard.keys.ENTER: this.togglePicker(); break; // Allows the "Escape" key to close the picker - case KEYCODES.ESCAPE: + case Keyboard.keys.ESCAPE: this.escape(); event.preventDefault(); break; @@ -65,13 +61,13 @@ class Picker { item.addEventListener('keydown', (event) => { switch(event.keyCode) { // Allows the "Enter" key to select an item - case KEYCODES.ENTER: + case Keyboard.keys.ENTER: this.selectItem(item, true); event.preventDefault(); break; // Allows the "Escape" key to close the picker - case KEYCODES.ESCAPE: + case Keyboard.keys.ESCAPE: this.escape(); event.preventDefault(); break;