Fix item custom template select bug

This commit is contained in:
Bohdan Kostko 2017-03-12 14:17:46 +01:00
parent 13afb13be7
commit c21893e6fa
5 changed files with 60 additions and 20 deletions

View file

@ -777,7 +777,7 @@ return /******/ (function(modules) { // webpackBootstrap
this.input.focus(); this.input.focus();
} }
(0, _utils.triggerEvent)(this.passedElement, "showDropdown", {}); (0, _utils.triggerEvent)(this.passedElement, 'showDropdown', {});
return this; return this;
} }
@ -809,7 +809,7 @@ return /******/ (function(modules) { // webpackBootstrap
this.input.blur(); this.input.blur();
} }
(0, _utils.triggerEvent)(this.passedElement, "hideDropdown", {}); (0, _utils.triggerEvent)(this.passedElement, 'hideDropdown', {});
return this; return this;
} }
@ -1811,11 +1811,12 @@ return /******/ (function(modules) { // webpackBootstrap
if (this.containerOuter.contains(target) && target !== this.input) { if (this.containerOuter.contains(target) && target !== this.input) {
var activeItems = this.store.getItemsFilteredByActive(); var activeItems = this.store.getItemsFilteredByActive();
var hasShiftKey = e.shiftKey; var hasShiftKey = e.shiftKey;
var foundTarget = void 0;
if (target.hasAttribute('data-item')) { if (foundTarget = (0, _utils.findAncestorByAttr)(target, 'data-item')) {
this._handleItemAction(activeItems, target, hasShiftKey); this._handleItemAction(activeItems, foundTarget, hasShiftKey);
} else if (target.hasAttribute('data-choice')) { } else if (foundTarget = (0, _utils.findAncestorByAttr)(target, 'data-choice')) {
this._handleChoiceAction(activeItems, target); this._handleChoiceAction(activeItems, foundTarget);
} }
e.preventDefault(); e.preventDefault();
@ -2670,10 +2671,7 @@ return /******/ (function(modules) { // webpackBootstrap
* @param {!Object<string, *>} options * @param {!Object<string, *>} options
*/ */
function Fuse (list, options) { function Fuse (list, options) {
var i
var len
var key var key
var keys
this.list = list this.list = list
this.options = options = options || {} this.options = options = options || {}
@ -2692,7 +2690,7 @@ return /******/ (function(modules) { // webpackBootstrap
} }
} }
Fuse.VERSION = '2.6.0' Fuse.VERSION = '2.6.2'
/** /**
* Sets a new list for Fuse to match against. * Sets a new list for Fuse to match against.
@ -5290,6 +5288,26 @@ return /******/ (function(modules) { // webpackBootstrap
return el; return el;
}; };
/**
* Find ancestor in DOM tree by attribute name
* @param {NodeElement} el Element to start search from
* @param {string} attr Attribute name of parent
* @return {?NodeElement} Found parent element or null
*/
var findAncestorByAttr = exports.findAncestorByAttr = function findAncestorByAttr(el, attr) {
var target = el;
while (target) {
if (target.hasAttribute(attr)) {
return target;
}
target = target.parentElement;
}
return null;
};
/** /**
* Debounce an event handler. * Debounce an event handler.
* @param {Function} func Function to run after wait * @param {Function} func Function to run after wait

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -25,6 +25,7 @@ import {
sortByAlpha, sortByAlpha,
sortByScore, sortByScore,
triggerEvent, triggerEvent,
findAncestorByAttr
} }
from './lib/utils.js'; from './lib/utils.js';
import './lib/polyfills.js'; import './lib/polyfills.js';
@ -653,7 +654,7 @@ class Choices {
this.input.focus(); this.input.focus();
} }
triggerEvent(this.passedElement, "showDropdown", {}); triggerEvent(this.passedElement, 'showDropdown', {});
return this; return this;
} }
@ -680,7 +681,7 @@ class Choices {
this.input.blur(); this.input.blur();
} }
triggerEvent(this.passedElement, "hideDropdown", {}); triggerEvent(this.passedElement, 'hideDropdown', {});
return this; return this;
} }
@ -1573,15 +1574,16 @@ class Choices {
* @private * @private
*/ */
_onMouseDown(e) { _onMouseDown(e) {
const target = e.target; let target = e.target;
if (this.containerOuter.contains(target) && target !== this.input) { if (this.containerOuter.contains(target) && target !== this.input) {
const activeItems = this.store.getItemsFilteredByActive(); const activeItems = this.store.getItemsFilteredByActive();
const hasShiftKey = e.shiftKey; const hasShiftKey = e.shiftKey;
let foundTarget;
if (target.hasAttribute('data-item')) { if (foundTarget = findAncestorByAttr(target, 'data-item')) {
this._handleItemAction(activeItems, target, hasShiftKey); this._handleItemAction(activeItems, foundTarget, hasShiftKey);
} else if (target.hasAttribute('data-choice')) { } else if (foundTarget = findAncestorByAttr(target, 'data-choice')) {
this._handleChoiceAction(activeItems, target); this._handleChoiceAction(activeItems, foundTarget);
} }
e.preventDefault(); e.preventDefault();

View file

@ -258,6 +258,26 @@ export const findAncestor = function(el, cls) {
return el; return el;
}; };
/**
* Find ancestor in DOM tree by attribute name
* @param {NodeElement} el Element to start search from
* @param {string} attr Attribute name of parent
* @return {?NodeElement} Found parent element or null
*/
export const findAncestorByAttr = function(el, attr) {
let target = el;
while (target) {
if (target.hasAttribute(attr)) {
return target;
}
target = target.parentElement;
}
return null;
};
/** /**
* Debounce an event handler. * Debounce an event handler.
* @param {Function} func Function to run after wait * @param {Function} func Function to run after wait