Skip to content

feat: add keyboard control to sliders#115

Merged
luwes merged 4 commits intomainfrom
fix-focus-hover
Oct 22, 2025
Merged

feat: add keyboard control to sliders#115
luwes merged 4 commits intomainfrom
fix-focus-hover

Conversation

@luwes
Copy link
Copy Markdown
Collaborator

@luwes luwes commented Oct 22, 2025

  • todo fix relative value bug in time slider and volume slider

@luwes luwes requested a review from Copilot October 22, 2025 17:31
@luwes luwes self-assigned this Oct 22, 2025
@vercel
Copy link
Copy Markdown

vercel bot commented Oct 22, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
vjs-10-demo-html Ready Ready Preview Comment Oct 22, 2025 10:10pm
vjs-10-demo-react Ready Ready Preview Comment Oct 22, 2025 10:10pm
vjs-10-website Ready Ready Preview Comment Oct 22, 2025 10:10pm

Copy link
Copy Markdown
Contributor

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.

Pull Request Overview

This PR adds keyboard navigation support to slider components (time and volume sliders), allowing users to control them using arrow keys, Home, and End keys. The implementation includes step size configuration and proper state management for keyboard interactions.

Key Changes:

  • Added keyboard event handling to the base Slider class with configurable step sizes
  • Integrated keyboard controls into TimeSlider and VolumeSlider components
  • Modified Popover component to disable focus management to prevent interference with keyboard navigation

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
packages/core/core/src/components/slider.ts Added keyboard event listeners, handlers for arrow/Home/End keys, and step size configuration
packages/core/core/src/components/time-slider.ts Extended keyboard handling to trigger seek operations based on keyboard input
packages/core/core/src/components/volume-slider.ts Extended keyboard handling to trigger volume changes and set default step size of 0.1
packages/react/react/src/components/Popover.tsx Disabled focus management and hover-based initial focus to prevent conflicts with keyboard controls

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread packages/react/react/src/components/Popover.tsx
Comment thread packages/core/core/src/components/slider.ts Outdated
Comment on lines +85 to +88
super.handleEvent(event);

const { _pointerRatio, requestVolumeChange } = super.getState() as VolumeSliderState;
requestVolumeChange(_pointerRatio);
Copy link

Copilot AI Oct 22, 2025

Choose a reason for hiding this comment

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

The keyboard event is passed to super.handleEvent(event) which updates _pointerRatio, but then getState() is called immediately after. Due to potential asynchronous state updates, _pointerRatio may not reflect the updated value from the keyboard handler. Consider getting the updated ratio directly from the parent's keyboard handler return value or accessing the updated state differently.

Suggested change
super.handleEvent(event);
const { _pointerRatio, requestVolumeChange } = super.getState() as VolumeSliderState;
requestVolumeChange(_pointerRatio);
// Compute the new pointer ratio synchronously based on the key event
const state = super.getState() as VolumeSliderState;
let newPointerRatio = state._pointerRatio;
// Example logic: adjust ratio based on arrow keys
if (event.key === 'ArrowLeft' || event.key === 'ArrowDown') {
newPointerRatio = Math.max(0, newPointerRatio - this.getStepSize());
} else if (event.key === 'ArrowRight' || event.key === 'ArrowUp') {
newPointerRatio = Math.min(1, newPointerRatio + this.getStepSize());
}
const { requestVolumeChange } = state;
requestVolumeChange(newPointerRatio);
// Optionally, update the pointer ratio in state if needed
// (depends on parent class implementation)
// super.setPointerRatio(newPointerRatio);

Copilot uses AI. Check for mistakes.
Comment on lines +99 to +106
#handleKeyDown(event: KeyboardEvent) {
super.handleEvent(event);

const { _pointerRatio, duration, requestSeek } = super.getState() as TimeSliderState;

this.#seekingTime = _pointerRatio * duration;
requestSeek(this.#seekingTime);
}
Copy link

Copilot AI Oct 22, 2025

Choose a reason for hiding this comment

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

Same issue as in VolumeSlider: calling getState() immediately after super.handleEvent(event) may not capture the updated _pointerRatio value if state updates are asynchronous. This aligns with the PR description's noted bug about 'relative value bug in time slider and volume slider'.

Copilot uses AI. Check for mistakes.
@vercel vercel bot temporarily deployed to Preview – vjs-10-demo-react October 22, 2025 21:02 Inactive
@vercel vercel bot temporarily deployed to Preview – vjs-10-demo-html October 22, 2025 21:02 Inactive
@vercel vercel bot temporarily deployed to Preview – vjs-10-website October 22, 2025 21:02 Inactive
@vercel vercel bot temporarily deployed to Preview – vjs-10-demo-html October 22, 2025 22:10 Inactive
@vercel vercel bot temporarily deployed to Preview – vjs-10-demo-react October 22, 2025 22:10 Inactive
@vercel vercel bot temporarily deployed to Preview – vjs-10-website October 22, 2025 22:10 Inactive
@luwes luwes marked this pull request as ready for review October 22, 2025 22:11
@luwes luwes merged commit 0a49026 into main Oct 22, 2025
4 checks passed
@luwes luwes deleted the fix-focus-hover branch October 22, 2025 22:12
@github-actions github-actions bot mentioned this pull request Oct 24, 2025
@github-actions github-actions bot mentioned this pull request Feb 26, 2026
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