Skip to content

fix: SliderControl CSS#487

Open
ExtraBinoss wants to merge 3 commits intowebadderallorg:mainfrom
ExtraBinoss:fix/css-slidercontrol
Open

fix: SliderControl CSS#487
ExtraBinoss wants to merge 3 commits intowebadderallorg:mainfrom
ExtraBinoss:fix/css-slidercontrol

Conversation

@ExtraBinoss
Copy link
Copy Markdown
Collaborator

@ExtraBinoss ExtraBinoss commented May 9, 2026

Summary

Slider control had issues in terms of CSS and possibly performance

Description

Here is a summary of the fixes and optimizations implemented for the SliderControl:

  1. Visual & Accuracy Fixes
    Removed 0% Clipping: Fixed a bug where the white handle would disappear at 0% due to an incorrect -8px offset. It now stays perfectly visible and aligned at the start.
    Eliminated the "15% Jump": Removed a hardcoded 2.1rem minimum width on the fill bar. The slider now scales linearly and accurately from 0 to 100%.
    Pixel-Perfect Inset: Corrected a CSS calculation error where offsets were being treated as percentages of the total width instead of fixed pixels (* 6px / 100%). This ensures the slider reaches the absolute visual end regardless of how wide the component is.

  2. Performance Optimizations
    Hybrid Rendering (React Bypass): The component now uses a high-performance "uncontrolled" model during interaction. It updates the DOM directly via CSS Variables (--slider-pct) and Refs, bypassing React's re-render cycle for zero-latency dragging.
    Layout Stability: Bounding box measurements are now cached on pointerdown. This prevents "layout thrashing" (repeatedly asking the browser for dimensions), which significantly reduces CPU load during movement.
    60fps+ Smoothness: Leveraged requestAnimationFrame and CSS hardware acceleration to ensure the smoothest possible visual feedback, even if the parent application is performing heavy background tasks.
    Memoization: Wrapped the component in React.memo to ensure it only re-renders when actual props change, keeping the main thread clear.

Type of Change

  • Bug Fix

Screenshots / Video

Before :
slidercontrol css issue

Now
volume-radius works
max css slider control

Summary by CodeRabbit

  • Refactor
    • Slider rewritten for smoother, more responsive dragging with reduced layout work and immediate visual feedback.
  • Accessibility
    • Improved live value reporting so assistive technologies receive up-to-date numeric values during interaction.
  • UX
    • Visual fill and divider update continuously during pointer drag for more accurate feedback.

Review Change Stack

Copilot AI review requested due to automatic review settings May 9, 2026 22:21
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 1f802201-66f9-4b08-8801-d29b3ff48a4b

📥 Commits

Reviewing files that changed from the base of the PR and between bc67434 and f092b1e.

📒 Files selected for processing (1)
  • src/components/video-editor/SliderControl.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/video-editor/SliderControl.tsx

📝 Walkthrough

Walkthrough

SliderControl is converted to a memo-wrapped component and now drives visuals with a CSS custom property (--slider-pct). Refs and useEffect perform DOM updates; pointer dragging caches bounds and throttles moves with requestAnimationFrame, updating ARIA/value text and calling onChange with quantized values.

Changes

SliderControl CSS-Driven Performance Refactor

Layer / File(s) Summary
Import Updates
src/components/video-editor/SliderControl.tsx
React imports expanded to include useEffect and memo hooks.
Component Structure & Refs
src/components/video-editor/SliderControl.tsx
Component converted to memo-wrapped const export with three new refs: valueTextRef, boundsRef, requestRef.
Effect & Value Update Logic
src/components/video-editor/SliderControl.tsx
useEffect syncs --slider-pct CSS custom property. updateValue quantizes/clamps values, updates DOM directly for feedback, then calls onChange.
Pointer Interaction & RAF Throttling
src/components/video-editor/SliderControl.tsx
Pointer-down handler caches bounding rect and throttles move updates with requestAnimationFrame. Cleanup cancels pending frames and releases pointer capture.
Visual Rendering & CSS Expressions
src/components/video-editor/SliderControl.tsx
Track/divider positioning switch to calc() expressions based on --slider-pct. Numeric display uses ref-backed span for direct updates.

🎯 4 (Complex) | ⏱️ ~45 minutes

I nibble on a CSS thread,
Throttle dance on rails of thread,
Refs keep bounds so light and neat,
RAF hums a steady beat,
Slider sings — small paws, big feat. 🐇✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'fix: SliderControl CSS' is vague and only partially reflects the main change—it mentions CSS but omits the significant performance optimizations (memoization, hybrid rendering, layout caching) that are central to this changeset. Revise the title to reflect both the visual fixes and performance optimizations, e.g., 'fix: SliderControl CSS alignment and performance with hybrid rendering' or 'refactor: SliderControl with CSS fixes and performance optimizations'.
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The pull request description is comprehensive, including detailed explanations of visual/accuracy fixes, performance optimizations, before/after screenshots, and type of change. It covers most key sections from the template.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Copy link
Copy Markdown
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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/components/video-editor/SliderControl.tsx (1)

137-160: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Add touch-none to the slider root to prevent mobile scrolling interference.

preventDefault() on pointerdown is insufficient to suppress browser pan/zoom gestures because modern browsers use passive event listeners by default, which ignore preventDefault(). This allows touch drags to get canceled into page scrolling on mobile devices. The touch-none CSS class (Tailwind's touch-action: none) is the proper solution and is already used in similar interactive components in this codebase.

Suggested fix
-			className="relative flex h-10 w-full select-none items-center overflow-hidden rounded-xl bg-editor-bg/80 px-1.5 outline-none focus-visible:ring-1 focus-visible:ring-[`#2563EB`]/40"
+			className="relative flex h-10 w-full touch-none select-none items-center overflow-hidden rounded-xl bg-editor-bg/80 px-1.5 outline-none focus-visible:ring-1 focus-visible:ring-[`#2563EB`]/40"
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/video-editor/SliderControl.tsx` around lines 137 - 160, The
root slider DIV (the element with role="slider" in SliderControl.tsx that uses
rootRef and handlePointerDown) needs the Tailwind touch-none class added to its
className to set touch-action: none so mobile pan/zoom/scroll gestures won’t
cancel slider drags; update the className for that root element to include
"touch-none" (keeping the existing classes and onPointerDown/handlePointerDown
logic intact).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/components/video-editor/SliderControl.tsx`:
- Around line 71-83: The fast-path DOM updates use the raw pointer-derived
currentPct instead of the step-snapped finalValue, causing the visual
fill/handle and ARIA attributes to lag; update the logic in SliderControl so you
compute the percentage from finalValue (using the same normalization used
elsewhere between min/max) and set
rootRef.current.style.setProperty("--slider-pct", `${snappedPct}%`) and update
valueTextRef.current.textContent and the element's ARIA attributes
(aria-valuenow / aria-valuetext) from formatValue(finalValue) before calling
onChange(finalValue); apply the identical change to the other fast-path block
referenced around lines 140-146.
- Around line 109-127: In finishPointer, ensure the final pointer position is
applied before tearing down: if finishEvent.pointerId === pointerId and the
event is a pointerup, call updateValue(finishEvent.clientX) (or otherwise flush
the last position) prior to canceling requestRef.current and removing listeners;
reference the finishPointer function, updateValue, requestRef, pointerId and
target to locate and place this call so quick drag-releases update the slider to
the final release position before cleanup.

---

Outside diff comments:
In `@src/components/video-editor/SliderControl.tsx`:
- Around line 137-160: The root slider DIV (the element with role="slider" in
SliderControl.tsx that uses rootRef and handlePointerDown) needs the Tailwind
touch-none class added to its className to set touch-action: none so mobile
pan/zoom/scroll gestures won’t cancel slider drags; update the className for
that root element to include "touch-none" (keeping the existing classes and
onPointerDown/handlePointerDown logic intact).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 3f8f1006-13e0-486a-998d-f0149fa45102

📥 Commits

Reviewing files that changed from the base of the PR and between f6a40d7 and fd9bd1a.

📒 Files selected for processing (1)
  • src/components/video-editor/SliderControl.tsx

Comment thread src/components/video-editor/SliderControl.tsx
Comment thread src/components/video-editor/SliderControl.tsx
Copy link
Copy Markdown
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.

🧹 Nitpick comments (1)
src/components/video-editor/SliderControl.tsx (1)

176-176: ⚡ Quick win

CSS calc expression uses invalid unit arithmetic—consider storing slider position as a decimal.

The calc expression (var(--slider-pct) * 6px / 100%) violates CSS spec constraints. Per CSS Values and Units, multiplication requires at least one operand to be a unitless <number>, but --slider-pct is stored as a percentage string (e.g., "50%"), making percentage * length invalid. Similarly, division requires the divisor to be unitless, so / 100% is also invalid. While some browsers may tolerate this through lenient parsing, it is not reliable.

To ensure spec compliance, store the slider position as a decimal (0–1) and adjust the calc expressions:

♻️ Suggested refactor

At line 57 (useEffect):

-rootRef.current.style.setProperty("--slider-pct", `${pct}%`);
+rootRef.current.style.setProperty("--slider-pct", String(pct / 100));

At line 76 (updateValue):

-rootRef.current.style.setProperty("--slider-pct", `${finalPct}%`);
+rootRef.current.style.setProperty("--slider-pct", String(Number(finalPct) / 100));

At line 169 (inline style):

-"--slider-pct": `${pct}%`,
+"--slider-pct": String(pct / 100),

At line 176:

-width: "calc(var(--slider-pct) - (var(--slider-pct) * 6px / 100%))",
+width: "calc(var(--slider-pct) * (100% - 6px))",

At line 185:

-left: "calc(2px + var(--slider-pct) - (var(--slider-pct) * 6px / 100%))",
+left: "calc(2px + var(--slider-pct) * (100% - 6px))",
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/video-editor/SliderControl.tsx` at line 176, The CSS calc is
invalid because --slider-pct is stored as a percentage string; change
--slider-pct to be a unitless decimal (0–1) everywhere (set in the useEffect
that initializes it and in updateValue), and update all uses (including the
inline style that sets width) to multiply that unitless value by lengths instead
of multiplying/dividing percentages; for example replace the width calc with:
use "calc(var(--slider-pct) * (100% - 6px))" (and adjust any other expressions
at the earlier useEffect and updateValue locations to read/set decimals rather
than "50%"/"%"-strings).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/components/video-editor/SliderControl.tsx`:
- Line 176: The CSS calc is invalid because --slider-pct is stored as a
percentage string; change --slider-pct to be a unitless decimal (0–1) everywhere
(set in the useEffect that initializes it and in updateValue), and update all
uses (including the inline style that sets width) to multiply that unitless
value by lengths instead of multiplying/dividing percentages; for example
replace the width calc with: use "calc(var(--slider-pct) * (100% - 6px))" (and
adjust any other expressions at the earlier useEffect and updateValue locations
to read/set decimals rather than "50%"/"%"-strings).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: e7759967-3ce1-4667-809e-0b486f965481

📥 Commits

Reviewing files that changed from the base of the PR and between fd9bd1a and bc67434.

📒 Files selected for processing (1)
  • src/components/video-editor/SliderControl.tsx

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants