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

⚗🐛 reset input state at the beginning of each click #1968

Merged
merged 2 commits into from
Jan 25, 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
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { resetExperimentalFeatures, updateExperimentalFeatures } from '@datadog/browser-core'
import type { Clock } from '../../../../../core/test/specHelper'
import { createNewEvent, mockClock } from '../../../../../core/test/specHelper'
import type { ActionEventsHooks } from './listenActionEvents'
Expand Down Expand Up @@ -180,10 +181,30 @@ describe('listenActionEvents', () => {
it('click that triggers an input event slightly after the click should report an input user activity', () => {
emulateClick()
emulateInputEvent()
clock.tick(1)
clock.tick(1) // run immediate timeouts
expect(hasInputUserActivity()).toBe(true)
})

describe('with fix_dead_clicks_after_input flag', () => {
beforeEach(() => {
stopListenEvents()

updateExperimentalFeatures(['fix_dead_clicks_after_input'])
;({ stop: stopListenEvents } = listenActionEvents(actionEventsHooks))
})

afterEach(() => {
resetExperimentalFeatures()
})

it('input events that precede clicks should not be taken into account', () => {
emulateInputEvent()
emulateClick()
clock.tick(1) // run immediate timeouts
expect(hasInputUserActivity()).toBe(false)
})
})

it('click and type should report an input user activity', () => {
emulateClick({
beforeMouseUp() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { addEventListener, DOM_EVENT, monitor } from '@datadog/browser-core'
import { addEventListener, DOM_EVENT, isExperimentalFeatureEnabled, monitor } from '@datadog/browser-core'

export type MouseEventOnElement = MouseEvent & { target: Element }

Expand All @@ -21,6 +21,9 @@ export function listenActionEvents<ClickContext>({ onPointerDown, onClick }: Act
(event) => {
hasSelectionChanged = false
selectionEmptyAtPointerDown = isSelectionEmpty()
if (isExperimentalFeatureEnabled('fix_dead_clicks_after_input')) {
hasInputChanged = false
}
if (isMouseEventOnElement(event)) {
clickContext = onPointerDown(event)
}
Expand Down