fix(button): put host element into click event target (fix #89)

This commit is contained in:
Mikhail Bashkirov 2019-07-12 15:29:56 +02:00
parent b71177f667
commit 59e456e11f
2 changed files with 12 additions and 0 deletions

View file

@ -159,9 +159,20 @@ export class LionButton extends DelegateMixin(SlotMixin(LionLitElement)) {
oldEvent.stopPropagation();
// replacing `MouseEvent` with `oldEvent.constructor` breaks IE
const newEvent = new MouseEvent(oldEvent.type, oldEvent);
this.__enforceHostEventTarget(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() {
this.addEventListener('keydown', this.__keydownDelegationHandler);
this.addEventListener('keyup', this.__keyupDelegationHandler);

View file

@ -194,6 +194,7 @@ describe('lion-button', () => {
'cancelable',
'clientX',
'clientY',
'target',
];
sameProperties.forEach(property => {