Commit cc6695c6 by Tim Krones

Address review comments.

parent 99929eae
...@@ -116,7 +116,8 @@ ...@@ -116,7 +116,8 @@
/* Focused option */ /* Focused option */
.xblock--drag-and-drop .drag-container .item-bank .option:focus, .xblock--drag-and-drop .drag-container .item-bank .option:focus,
.xblock--drag-and-drop .drag-container .item-bank .option:hover { .xblock--drag-and-drop .drag-container .item-bank .option:hover,
.xblock--drag-and-drop .drag-container .item-bank .option[aria-grabbed='true'] {
outline-width: 2px; outline-width: 2px;
outline-style: solid; outline-style: solid;
outline-offset: -4px; outline-offset: -4px;
......
...@@ -13,7 +13,6 @@ function DragAndDropBlock(runtime, element, configuration) { ...@@ -13,7 +13,6 @@ function DragAndDropBlock(runtime, element, configuration) {
var __vdom = virtualDom.h(); // blank virtual DOM var __vdom = virtualDom.h(); // blank virtual DOM
// Keyboard accessibility // Keyboard accessibility
var CTRL = 17;
var ESC = 27; var ESC = 27;
var RET = 13; var RET = 13;
var SPC = 32; var SPC = 32;
...@@ -21,7 +20,6 @@ function DragAndDropBlock(runtime, element, configuration) { ...@@ -21,7 +20,6 @@ function DragAndDropBlock(runtime, element, configuration) {
var M = 77; var M = 77;
var QUESTION_MARK = 63; var QUESTION_MARK = 63;
var ctrlDown = false;
var placementMode = false; var placementMode = false;
var $selectedItem; var $selectedItem;
var $focusedElement; var $focusedElement;
...@@ -213,16 +211,17 @@ function DragAndDropBlock(runtime, element, configuration) { ...@@ -213,16 +211,17 @@ function DragAndDropBlock(runtime, element, configuration) {
}); });
}; };
var isCycleKey = function(key) { var isCycleKey = function(evt) {
return !ctrlDown && key === TAB; return !evt.ctrlKey && !evt.metaKey && evt.which === TAB;
}; };
var isCancelKey = function(key) { var isCancelKey = function(evt) {
return !ctrlDown && key === ESC; return !evt.ctrlKey && !evt.metaKey && evt.which === ESC;
}; };
var isActionKey = function(key) { var isActionKey = function(evt) {
if (ctrlDown) { var key = evt.which;
if (evt.ctrlKey || evt.metaKey) {
return key === M; return key === M;
} }
return key === RET || key === SPC; return key === RET || key === SPC;
...@@ -286,28 +285,20 @@ function DragAndDropBlock(runtime, element, configuration) { ...@@ -286,28 +285,20 @@ function DragAndDropBlock(runtime, element, configuration) {
var $zone = $(this); var $zone = $(this);
$zone.on('keydown', function(evt) { $zone.on('keydown', function(evt) {
if (placementMode) { if (placementMode) {
var key = evt.which; if (isCycleKey(evt)) {
if (key === CTRL) {
ctrlDown = true;
return;
}
if (isCycleKey(key)) {
focusNextZone(evt, $zone); focusNextZone(evt, $zone);
} else if (isCancelKey(key)) { } else if (isCancelKey(evt)) {
evt.preventDefault(); evt.preventDefault();
placementMode = false; placementMode = false;
} else if (isActionKey(key)) { releaseItem($selectedItem);
} else if (isActionKey(evt)) {
evt.preventDefault(); evt.preventDefault();
placementMode = false; placementMode = false;
placeItem($zone); placeItem($zone);
releaseItem($selectedItem);
} }
} }
}); });
$zone.on('keyup', function(evt) {
if (evt.which === CTRL) {
ctrlDown = false;
}
});
}); });
// Make zone accept items that are dropped using the mouse // Make zone accept items that are dropped using the mouse
...@@ -328,23 +319,14 @@ function DragAndDropBlock(runtime, element, configuration) { ...@@ -328,23 +319,14 @@ function DragAndDropBlock(runtime, element, configuration) {
// Allow item to be "picked up" using the keyboard // Allow item to be "picked up" using the keyboard
$item.on('keydown', function(evt) { $item.on('keydown', function(evt) {
var key = evt.which; if (isActionKey(evt)) {
if (key === CTRL) {
ctrlDown = true;
return;
}
if (isActionKey(key)) {
evt.preventDefault(); evt.preventDefault();
placementMode = true; placementMode = true;
grabItem($item);
$selectedItem = $item; $selectedItem = $item;
$root.find('.target .zone').first().focus(); $root.find('.target .zone').first().focus();
} }
}); });
$item.on('keyup', function(evt) {
if (evt.which === CTRL) {
ctrlDown = false;
}
});
// Make item draggable using the mouse // Make item draggable using the mouse
try { try {
...@@ -355,18 +337,15 @@ function DragAndDropBlock(runtime, element, configuration) { ...@@ -355,18 +337,15 @@ function DragAndDropBlock(runtime, element, configuration) {
revert: 'invalid', revert: 'invalid',
revertDuration: 150, revertDuration: 150,
start: function(evt, ui) { start: function(evt, ui) {
var item_id = $(this).data('value'); var $item = $(this);
setGrabbedState(item_id, true); grabItem($item);
updateDOM();
publishEvent({ publishEvent({
event_type: 'xblock.drag-and-drop-v2.item.picked-up', event_type: 'xblock.drag-and-drop-v2.item.picked-up',
item_id: item_id item_id: $item.data('value'),
}); });
}, },
stop: function(evt, ui) { stop: function(evt, ui) {
var item_id = $(this).data('value'); releaseItem($(this));
setGrabbedState(item_id, false);
updateDOM();
} }
}); });
} catch (e) { } catch (e) {
...@@ -376,6 +355,18 @@ function DragAndDropBlock(runtime, element, configuration) { ...@@ -376,6 +355,18 @@ function DragAndDropBlock(runtime, element, configuration) {
}); });
}; };
var grabItem = function($item) {
var item_id = $item.data('value');
setGrabbedState(item_id, true);
updateDOM();
};
var releaseItem = function($item) {
var item_id = $item.data('value');
setGrabbedState(item_id, false);
updateDOM();
};
var setGrabbedState = function(item_id, grabbed) { var setGrabbedState = function(item_id, grabbed) {
for (var i = 0; i < configuration.items.length; i++) { for (var i = 0; i < configuration.items.length; i++) {
if (configuration.items[i].id === item_id) { if (configuration.items[i].id === item_id) {
...@@ -524,10 +515,11 @@ function DragAndDropBlock(runtime, element, configuration) { ...@@ -524,10 +515,11 @@ function DragAndDropBlock(runtime, element, configuration) {
if (item.grabbed !== undefined) { if (item.grabbed !== undefined) {
grabbed = item.grabbed; grabbed = item.grabbed;
} }
var placed = item_user_state && ('input' in item_user_state || item_user_state.correct_input);
var itemProperties = { var itemProperties = {
value: item.id, value: item.id,
drag_disabled: Boolean(item_user_state || state.finished), drag_disabled: Boolean(item_user_state || state.finished),
class_name: item_user_state && ('input' in item_user_state || item_user_state.correct_input) ? 'fade': undefined, class_name: placed || state.finished ? 'fade' : undefined,
xhr_active: (item_user_state && item_user_state.submitting_location), xhr_active: (item_user_state && item_user_state.submitting_location),
input: input, input: input,
displayName: item.displayName, displayName: item.displayName,
......
...@@ -176,8 +176,8 @@ ...@@ -176,8 +176,8 @@
h('p', gettext('You can complete this exercise using only your keyboard.')), h('p', gettext('You can complete this exercise using only your keyboard.')),
h('ul', [ h('ul', [
h('li', gettext('Use "Tab" and "Shift-Tab" to navigate between items and zones.')), h('li', gettext('Use "Tab" and "Shift-Tab" to navigate between items and zones.')),
h('li', gettext('Press "Enter" or "Space" on an item to select it for dropping, then navigate to the zone you want to drop it on.')), h('li', gettext('Press "Enter", "Space", "Ctrl-m", or "⌘-m" on an item to select it for dropping, then navigate to the zone you want to drop it on.')),
h('li', gettext('Press "Enter" or "Space" to drop the item on the current zone.')), h('li', gettext('Press "Enter", "Space", "Ctrl-m", or "⌘-m" to drop the item on the current zone.')),
h('li', gettext('Press "Escape" if you want to cancel the drop operation (e.g. because you would like to select a different item).')), h('li', gettext('Press "Escape" if you want to cancel the drop operation (e.g. because you would like to select a different item).')),
h('li', gettext('Press "?" at any time to bring up this dialog.')), h('li', gettext('Press "?" at any time to bring up this dialog.')),
]) ])
......
...@@ -72,6 +72,9 @@ class BaseIntegrationTest(SeleniumBaseTest): ...@@ -72,6 +72,9 @@ class BaseIntegrationTest(SeleniumBaseTest):
def _get_keyboard_help_dialog(self): def _get_keyboard_help_dialog(self):
return self._page.find_element_by_css_selector(".keyboard-help .keyboard-help-dialog") return self._page.find_element_by_css_selector(".keyboard-help .keyboard-help-dialog")
def _get_reset_button(self):
return self._page.find_element_by_css_selector('.reset-button')
def _get_feedback(self): def _get_feedback(self):
return self._page.find_element_by_css_selector(".feedback") return self._page.find_element_by_css_selector(".feedback")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment