Skip to content

Conversation

@bfoxx1906
Copy link
Contributor

@bfoxx1906 bfoxx1906 commented Dec 9, 2025

What:

  • Stops mousedown events from propagating from the sidebar button in ContentPreview
  • Converts the test to use RTL and removes snaphots

Why:

When the sidebar button is clicked it bubbles up the mousedown event to box-annotations which causes the current annotation to disappear. This PR stops mousedown events from propagating up the dom so that the current annotation remains displayed. Additionally, I converted the SidebarToggleButton tests to use RTL instead of enzyme and removed the snapshot testing as this is the direction that we want to go with our unit tests.

Before:

2025-12-09 12 19 19

After:

2025-12-09 12 17 20

Mobile Before:

2025-12-09 12 27 51

Mobile After:

2025-12-09 12 25 41

Summary by CodeRabbit

  • Bug Fixes

    • Prevented mousedown from propagating on the sidebar toggle button to avoid unintended interactions with parent annotations and video controls.
  • Tests

    • Modernized tests: replaced snapshots with DOM-focused assertions, added parametric coverage for open/state and modernization-flag combinations, and validated event propagation, class toggling, and click behavior.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 9, 2025

Walkthrough

Adds a mousedown handler that stops event propagation and attaches it to the modernized and legacy tooltip/button wrappers in SidebarToggleButton. Replaces snapshot tests with React Testing Library parametric tests that cover isOpen, direction, feature-flagged modernized rendering, and mousedown propagation behavior.

Changes

Cohort / File(s) Change Summary
Component Implementation
src/components/sidebar-toggle-button/SidebarToggleButton.js
Adds mouseDownHandler that calls event.stopPropagation() and attaches it to the modernized BPTooltip wrapper, the legacy surrounding span, and the PlainButton in both render paths; preserves existing props and rendering.
Test Refactoring
src/components/sidebar-toggle-button/__tests__/SidebarToggleButton.test.js
Replaces snapshot tests with React Testing Library queries and test.each parametric tests covering isOpen, direction, and isPreviewModernizationEnabled; adds assertions for mousedown propagation, modernized class toggling, icon presence, collapsed state, and click handler invocation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Verify mouseDownHandler is attached to the exact DOM elements used in both modernized and legacy branches.
  • Confirm tests simulate mousedown (not only click) and assert propagation behavior for both feature-flag states.
  • Check CSS/class assertions for the modernized toggle class and icon presence align with implementation.

Possibly related PRs

Suggested labels

ready-to-merge

Suggested reviewers

  • tjuanitas
  • JChan106

Poem

🐰 I nibbled on a noisy click,
With one small paw I made it stick.
Tests now listen, mousedown stays,
No more jumps or startled plays —
Sidebar quiet, mission quick.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: preventing mousedown event propagation on the sidebar button to fix video annotation behavior.
Description check ✅ Passed The description provides clear what/why context, detailed visual evidence, and aligns with the changes in the code summary. It covers both the functional fix and test refactoring work.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@bfoxx1906 bfoxx1906 changed the title fix(video-annotations: sidebar button fix to not propagate mousedown event fix(video-annotations): sidebar button fix to not propagate mousedown event Dec 9, 2025
@bfoxx1906 bfoxx1906 marked this pull request as ready for review December 9, 2025 17:36
@bfoxx1906 bfoxx1906 requested a review from a team as a code owner December 9, 2025 17:36
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/components/sidebar-toggle-button/__tests__/SidebarToggleButton.test.js (1)

8-38: Expand test coverage to include previewModernization feature flag.

This parametric test only covers isPreviewModernizationEnabled: false. Consider extending the test matrix to also cover isPreviewModernizationEnabled: true to ensure icon rendering and collapsed state work correctly in both modernized and legacy paths.

Apply this diff to expand the test matrix:

     test.each`
-        isOpen   | direction
-        ${true}  | ${'left'}
-        ${false} | ${'left'}
-        ${true}  | ${'right'}
-        ${false} | ${'right'}
+        isOpen   | direction  | isPreviewModernizationEnabled
+        ${true}  | ${'left'}  | ${false}
+        ${false} | ${'left'}  | ${false}
+        ${true}  | ${'right'} | ${false}
+        ${false} | ${'right'} | ${false}
+        ${true}  | ${'left'}  | ${true}
+        ${false} | ${'left'}  | ${true}
+        ${true}  | ${'right'} | ${true}
+        ${false} | ${'right'} | ${true}
     `(
-        'should render correct button correctly when open is $isOpen and direction is $direction and isPreviewModernizationEnabled is false',
-        ({ isOpen, direction }) => {
+        'should render correct button correctly when open is $isOpen and direction is $direction and isPreviewModernizationEnabled is $isPreviewModernizationEnabled',
+        ({ isOpen, direction, isPreviewModernizationEnabled }) => {
             render(<SidebarToggleButton isOpen={isOpen} direction={direction} />, {
-                wrapperProps: { features: { previewModernization: { enabled: false } } },
+                wrapperProps: { features: { previewModernization: { enabled: isPreviewModernizationEnabled } } },
             });
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5653500 and e1fc472.

⛔ Files ignored due to path filters (1)
  • src/components/sidebar-toggle-button/__tests__/__snapshots__/SidebarToggleButton.test.js.snap is excluded by !**/*.snap
📒 Files selected for processing (2)
  • src/components/sidebar-toggle-button/SidebarToggleButton.js (1 hunks)
  • src/components/sidebar-toggle-button/__tests__/SidebarToggleButton.test.js (1 hunks)
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: fpan225
Repo: box/box-ui-elements PR: 4239
File: src/elements/content-sidebar/SidebarNav.js:94-106
Timestamp: 2025-09-03T18:10:29.467Z
Learning: In the ContentSidebar CustomSidebarPanel API, the navButtonProps spread should come after explicit data-* attributes to allow users to override analytics tracking attributes like data-resin-target, data-target-id, and data-testid when needed. This is intentional API design for flexibility.
Learnt from: bxie-box
Repo: box/box-ui-elements PR: 4250
File: src/features/classification/applied-by-ai-classification-reason/__tests__/AppliedByAiClassificationReason.test.tsx:44-51
Timestamp: 2025-08-27T17:03:48.322Z
Learning: In test files for bxie-box, prefer using queryByTestId over getByTestId when testing for expected elements that should always exist, as null access serves as validation for regressions or unexpected changes rather than masking issues with defensive assertions.
Learnt from: fpan225
Repo: box/box-ui-elements PR: 4239
File: src/elements/content-sidebar/SidebarNav.js:195-206
Timestamp: 2025-09-03T18:10:42.760Z
Learning: In src/elements/content-sidebar/SidebarNav.js, the maintainer wants users to be able to override data-* attributes (data-resin-target, data-target-id, data-testid) through navButtonProps for custom tabs. The spread of {...navButtonProps} should come after the data-* attributes to allow overriding, not before them.
📚 Learning: 2025-09-03T18:10:29.467Z
Learnt from: fpan225
Repo: box/box-ui-elements PR: 4239
File: src/elements/content-sidebar/SidebarNav.js:94-106
Timestamp: 2025-09-03T18:10:29.467Z
Learning: In the ContentSidebar CustomSidebarPanel API, the navButtonProps spread should come after explicit data-* attributes to allow users to override analytics tracking attributes like data-resin-target, data-target-id, and data-testid when needed. This is intentional API design for flexibility.

Applied to files:

  • src/components/sidebar-toggle-button/SidebarToggleButton.js
📚 Learning: 2025-09-03T18:10:42.760Z
Learnt from: fpan225
Repo: box/box-ui-elements PR: 4239
File: src/elements/content-sidebar/SidebarNav.js:195-206
Timestamp: 2025-09-03T18:10:42.760Z
Learning: In src/elements/content-sidebar/SidebarNav.js, the maintainer wants users to be able to override data-* attributes (data-resin-target, data-target-id, data-testid) through navButtonProps for custom tabs. The spread of {...navButtonProps} should come after the data-* attributes to allow overriding, not before them.

Applied to files:

  • src/components/sidebar-toggle-button/SidebarToggleButton.js
  • src/components/sidebar-toggle-button/__tests__/SidebarToggleButton.test.js
📚 Learning: 2025-08-27T17:03:48.322Z
Learnt from: bxie-box
Repo: box/box-ui-elements PR: 4250
File: src/features/classification/applied-by-ai-classification-reason/__tests__/AppliedByAiClassificationReason.test.tsx:44-51
Timestamp: 2025-08-27T17:03:48.322Z
Learning: In test files for bxie-box, prefer using queryByTestId over getByTestId when testing for expected elements that should always exist, as null access serves as validation for regressions or unexpected changes rather than masking issues with defensive assertions.

Applied to files:

  • src/components/sidebar-toggle-button/__tests__/SidebarToggleButton.test.js
🧬 Code graph analysis (2)
src/components/sidebar-toggle-button/SidebarToggleButton.js (2)
src/elements/content-sidebar/SidebarNav.js (1)
  • isPreviewModernizationEnabled (139-139)
src/elements/content-sidebar/additional-tabs/AdditionalTabTooltip.js (1)
  • isPreviewModernizationEnabled (23-23)
src/components/sidebar-toggle-button/__tests__/SidebarToggleButton.test.js (1)
src/components/sidebar-toggle-button/SidebarToggleButton.js (3)
  • SidebarToggleButton (27-93)
  • isCollapsed (36-36)
  • isPreviewModernizationEnabled (35-35)
🪛 Biome (2.1.2)
src/components/sidebar-toggle-button/SidebarToggleButton.js

[error] 54-54: Type annotations are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.

TypeScript only syntax

(parse)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Summary
🔇 Additional comments (3)
src/components/sidebar-toggle-button/__tests__/SidebarToggleButton.test.js (1)

40-58: LGTM! Excellent test for event propagation.

The test correctly verifies that mousedown events do not propagate from the sidebar button to parent elements, covering both feature flag states. This directly validates the fix for the video annotations issue described in the PR.

src/components/sidebar-toggle-button/SidebarToggleButton.js (2)

54-56: Remove Flow type annotation from .js file.

Flow type annotations are not valid in plain JavaScript files. Either remove the type annotation or convert the file to TypeScript (.ts/.tsx).

Apply this diff to remove the Flow annotation:

-    const mouseDownHandler = (event: SyntheticMouseEvent<HTMLButtonElement>) => {
+    const mouseDownHandler = (event) => {

Note: The static analysis tool flagged this as a parse error.

⛔ Skipped due to learnings
Learnt from: rafalmaksymiuk
Repo: box/box-ui-elements PR: 4160
File: src/elements/content-sidebar/SidebarToggle.js:21-27
Timestamp: 2025-06-25T13:09:54.538Z
Learning: The box-ui-elements project uses Flow for type annotations in JavaScript files, as indicated by flow directives in file headers. Type annotations like `: Props` are valid Flow syntax, not TypeScript syntax.
Learnt from: rafalmaksymiuk
Repo: box/box-ui-elements PR: 4160
File: src/elements/content-sidebar/SidebarToggle.js:13-19
Timestamp: 2025-06-25T13:09:45.168Z
Learning: Files with `flow` or `flow strict` comments at the top use Flow type syntax, not TypeScript. Flow type definitions like `type Props = { ... }` and type imports like `type { RouterHistory }` are valid Flow syntax and should not be flagged as TypeScript-only features.
Learnt from: rafalmaksymiuk
Repo: box/box-ui-elements PR: 4160
File: src/elements/content-sidebar/SidebarToggle.js:11-11
Timestamp: 2025-06-25T13:10:19.128Z
Learning: In the box-ui-elements codebase, Flow files support `import type` syntax for type-only imports. The `import type` statement is valid Flow syntax, not just TypeScript, and should not be flagged as an error when used in Flow files (indicated by flow comments).
Learnt from: rafalmaksymiuk
Repo: box/box-ui-elements PR: 4144
File: src/elements/content-sidebar/versions/VersionsList.js:24-33
Timestamp: 2025-06-17T13:30:02.172Z
Learning: In the box-ui-elements codebase, Flow components use .flow.js type definition files, not TypeScript .ts files. The InternalSidebarNavigation type is a union type where different variants may have different properties like versionId, and proper type safety is ensured through conditional checks in methods like getSelectedVersionId.

62-76: Consider the interaction between onMouseDown and Blueprint's light-dismiss behavior.

The mousedown handler is attached to the BPTooltip wrapper, which may interfere with Blueprint's light-dismiss detection that relies on pointer events. Additionally, onMouseDown is redundantly attached to three elements (BPTooltip, span, and PlainButton)—consolidate to only the element that needs to handle the interaction. If the tooltip closes unexpectedly on mousedown, you may need to call event.stopPropagation() to prevent the event from triggering light-dismiss.

bfoxx1906 and others added 2 commits December 9, 2025 12:42
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
…tton.test.js

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
coderabbitai[bot]

This comment was marked as resolved.

JChan106

This comment was marked as resolved.

jpan-box

This comment was marked as resolved.

@bfoxx1906 bfoxx1906 dismissed stale reviews from jpan-box and JChan106 via cd67036 December 10, 2025 19:11
coderabbitai[bot]

This comment was marked as resolved.

Copy link
Contributor

@JChan106 JChan106 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mergify mergify bot added the queued label Dec 10, 2025
@mergify mergify bot merged commit 454ede0 into box:master Dec 10, 2025
8 checks passed
@mergify
Copy link
Contributor

mergify bot commented Dec 10, 2025

Merge Queue Status

✅ The pull request has been merged at cd67036

This pull request spent 6 seconds in the queue, with no time running CI.
The checks were run in-place.

Required conditions to merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants