-
-
Save lacek/010664dcf934cb17c780966c86e00684 to your computer and use it in GitHub Desktop.
power-select mouse bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import TriggerComponent from 'ember-power-select/components/power-select-multiple/trigger'; | |
const isTouchDevice = !!window && 'ontouchstart' in window; | |
export default TriggerComponent.extend({ | |
layoutName: 'components/trigger', | |
didInsertElement() { | |
let select = this.get('select'); | |
this.input = document.getElementById(`ember-power-select-trigger-multiple-input-${select.uniqueId}`); | |
let inputStyle = this.input ? window.getComputedStyle(this.input) : null; | |
this.inputFont = inputStyle ? `${ inputStyle.fontStyle } ${ inputStyle.fontVariant} ${ inputStyle.fontWeight } ${ inputStyle.fontSize}/${ inputStyle.lineHeight } ${ inputStyle.fontFamily }` : null; | |
let optionsList = document.getElementById(`ember-power-select-multiple-options-${select.uniqueId}`); | |
let stop = e => { | |
let selectedIndex = e.target.getAttribute('data-selected-index'); | |
if (selectedIndex) { | |
e.stopPropagation(); | |
e.preventDefault(); | |
} | |
}; | |
let chooseOption = (e) => { | |
let selectedIndex = e.target.getAttribute('data-selected-index'); | |
if (selectedIndex) { | |
e.stopPropagation(); | |
e.preventDefault(); | |
let select = this.get('select'); | |
let object = this.selectedObject(select.selected, selectedIndex); | |
select.actions.choose(object); | |
} | |
}; | |
if (isTouchDevice) { | |
optionsList.addEventListener('touchstart', stop); | |
optionsList.addEventListener('touchend', chooseOption); | |
} | |
optionsList.addEventListener('mousedown', stop); | |
optionsList.addEventListener('mouseup', chooseOption); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
init() { | |
this._super(); | |
this.catalog = [ | |
'Reese\'s pieces', | |
'Blow Pops', | |
'Almond Joy', | |
'M&Ms', | |
'Snickers', | |
'Mr. Goodbar' | |
]; | |
this.selected = [ | |
'Reese\'s pieces', | |
'Blow Pops' | |
]; | |
this.events = []; | |
}, | |
workaround: true, | |
actions: { | |
registerChange(values = []) { | |
this.get('events').pushObject(`Power Select changed [${values.join()}]`); | |
this.set('selected', values); | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.17.0", | |
"EmberENV": { | |
"FEATURES": {}, | |
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false, | |
"_APPLICATION_TEMPLATE_WRAPPER": true, | |
"_JQUERY_INTEGRATION": true | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js", | |
"ember": "2.18.2", | |
"ember-template-compiler": "2.18.2", | |
"ember-testing": "2.18.2" | |
}, | |
"addons": { | |
"@glimmer/component": "1.0.0", | |
"ember-power-select": "2.3.5" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment