fix(button): put host element into click event target (fix #89)
This commit is contained in:
parent
b71177f667
commit
59e456e11f
2 changed files with 12 additions and 0 deletions
|
|
@ -159,9 +159,20 @@ export class LionButton extends DelegateMixin(SlotMixin(LionLitElement)) {
|
||||||
oldEvent.stopPropagation();
|
oldEvent.stopPropagation();
|
||||||
// replacing `MouseEvent` with `oldEvent.constructor` breaks IE
|
// replacing `MouseEvent` with `oldEvent.constructor` breaks IE
|
||||||
const newEvent = new MouseEvent(oldEvent.type, oldEvent);
|
const newEvent = new MouseEvent(oldEvent.type, oldEvent);
|
||||||
|
this.__enforceHostEventTarget(newEvent);
|
||||||
this.$$slot('_button').dispatchEvent(newEvent);
|
this.$$slot('_button').dispatchEvent(newEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__enforceHostEventTarget(event) {
|
||||||
|
try {
|
||||||
|
// this is for IE11 (and works in others), because `Object.defineProperty` does not give any effect there
|
||||||
|
event.__defineGetter__('target', () => this); // eslint-disable-line no-restricted-properties
|
||||||
|
} catch (error) {
|
||||||
|
// in case `__defineGetter__` is removed from the platform
|
||||||
|
Object.defineProperty(event, 'target', { writable: false, value: this });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
__setupDelegation() {
|
__setupDelegation() {
|
||||||
this.addEventListener('keydown', this.__keydownDelegationHandler);
|
this.addEventListener('keydown', this.__keydownDelegationHandler);
|
||||||
this.addEventListener('keyup', this.__keyupDelegationHandler);
|
this.addEventListener('keyup', this.__keyupDelegationHandler);
|
||||||
|
|
|
||||||
|
|
@ -194,6 +194,7 @@ describe('lion-button', () => {
|
||||||
'cancelable',
|
'cancelable',
|
||||||
'clientX',
|
'clientX',
|
||||||
'clientY',
|
'clientY',
|
||||||
|
'target',
|
||||||
];
|
];
|
||||||
|
|
||||||
sameProperties.forEach(property => {
|
sameProperties.forEach(property => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue