Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove fix resolved by Mozilla three years ago #1660

Merged
merged 3 commits into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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