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

fix: don't track clicks on disabled elements #2468

Merged
merged 3 commits into from
Aug 31, 2023
Merged
Changes from 1 commit
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
10 changes: 7 additions & 3 deletions src/components/common/Track/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ type Props = {
label?: EventLabel
}

const shouldTrack = (el: HTMLDivElement) => {
const disabledChildren = el.querySelectorAll('*[disabled]')
return disabledChildren.length === 0
katspaugh marked this conversation as resolved.
Show resolved Hide resolved
}

const Track = ({ children, as: Wrapper = 'span', ...trackData }: Props): typeof children => {
const el = useRef<HTMLDivElement>(null)

Expand All @@ -20,9 +25,8 @@ const Track = ({ children, as: Wrapper = 'span', ...trackData }: Props): typeof

const trackEl = el.current

const handleClick = (e: MouseEvent) => {
// If clicked target is disabled, event.target will be trackEl
if (e.target !== trackEl) {
const handleClick = () => {
if (shouldTrack(trackEl)) {
trackEvent(trackData)
}
}
Expand Down
Loading