Skip to content

Commit

Permalink
Remove fix resolved by Mozilla three years ago (#1660)
Browse files Browse the repository at this point in the history
* Mozilla marked bug as resolved three years ago so the fix should be generally available

* Fixed linting errors

---------

Co-authored-by: Sampo Kivistö <[email protected]>
  • Loading branch information
jhsware and Havunen authored Dec 17, 2023
1 parent 915a6c5 commit 8d0afbe
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 61 deletions.
40 changes: 0 additions & 40 deletions packages/inferno/__tests__/instancenull.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -424,46 +424,6 @@ describe('BUG: instance - null', () => {
expect(container.innerHTML).toBe('');
});

it('Should not propagate mid/right mouse buttons clicks', (done) => {
const obj = {
spy() {},
};
const spy = spyOn(obj, 'spy');

render(
<div>
<div onClick={spy} id="MAGICBUTTON">
test
</div>
</div>,
container,
);

const event = document.createEvent('MouseEvents');
// Simulate right click
Object.defineProperty(event, 'button', {
value: 2,
});

// If changing button for click event is not supported, then we can skip this test.
if (event.button === 0) {
done();
return;
}

event.initEvent('click', true, true);

expect(spy.calls.count()).toBe(0);

const node = container.querySelector('#MAGICBUTTON');
node.dispatchEvent(event);

setTimeout(function () {
expect(spy.calls.count()).toBe(0);
done();
}, 10);
});

it('Should not fail #2', () => {
const items = [
{
Expand Down
25 changes: 4 additions & 21 deletions packages/inferno/src/DOM/events/delegation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,34 +174,17 @@ function extendEventProperties(event): IEventData {
return eventData;
}

function rootClickEvent(name: string) {
return function (event) {
if (event.button !== 0) {
// Firefox incorrectly triggers click event for mid/right mouse buttons.
// This bug has been active for 17 years.
// https://bugzilla.mozilla.org/show_bug.cgi?id=184051
event.stopPropagation();
return;
}

dispatchEvents(event, true, name, extendEventProperties(event));
};
}

function rootEvent(name: string) {
function rootEvent(name: string): (event: SemiSyntheticEvent<any>) => void {
const isClick = name === 'onClick' || name === 'onDblClick';
return function (event: SemiSyntheticEvent<any>) {
dispatchEvents(event, false, name, extendEventProperties(event));
dispatchEvents(event, isClick, name, extendEventProperties(event));
};
}

function attachEventToDocument(
name: string,
): (event: SemiSyntheticEvent<any>) => void {
const attachedEvent =
name === 'onClick' || name === 'onDblClick'
? rootClickEvent(name)
: rootEvent(name);

const attachedEvent = rootEvent(name);
// @ts-expect-error TODO: FIXME
document.addEventListener(normalizeEventName(name), attachedEvent);

Expand Down

0 comments on commit 8d0afbe

Please sign in to comment.