Skip to content

Commit

Permalink
Add support for click selection when selection-follows-focus is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
dotherightthing committed Sep 23, 2020
1 parent e3203cb commit a0c86fe
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions js/classes/keyboard-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class KeyboardHelpers {
// private options

this.proxyActionElements = {
selectFocussed: '[data-kh-proxy="selectFocussed"]',
selectNext: '[data-kh-proxy="selectNext"]',
selectPrevious: '[data-kh-proxy="selectPrevious"]'
};
Expand Down Expand Up @@ -384,11 +385,20 @@ class KeyboardHelpers {
registerProxyKeyboardActions() {
const proxyActions = Object.keys(this.proxyActionElements);

if (!this.selectionFollowsFocus) {
this.keyboardNavigableElements.forEach((keyboardNavigableElement) => {
// select on click
keyboardNavigableElement.setAttribute('data-kh-proxy', 'selectFocussed');
});
}

proxyActions.forEach((proxyAction) => {
const proxyActionElement = document.querySelector(`#${this.instanceId} ${this.proxyActionElements[proxyAction]}`);
const proxyActionElements = document.querySelectorAll(`#${this.instanceId} ${this.proxyActionElements[proxyAction]}`);

if (proxyActionElement !== null) {
proxyActionElement.addEventListener('click', this[proxyAction].bind(this));
if (proxyActionElements.length) {
proxyActionElements.forEach((proxyActionElement) => {
proxyActionElement.addEventListener('click', this[proxyAction].bind(this));
});
}
});
}
Expand Down Expand Up @@ -416,6 +426,11 @@ class KeyboardHelpers {

focussed.setAttribute(selectedAttrProp, selectedAttrVal);

// if focus was result of a click action
if (!this.selectionFollowsFocus) {
this.updateRovingTabIndex(focussed);
}

if (typeof e === 'object') {
if (this.toggleAfterSelected) {
this.toggleClosed();
Expand Down

0 comments on commit a0c86fe

Please sign in to comment.