Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@leonvogt
Copy link
Contributor

This PR contains a:

  • bugfix
  • new feature
  • code refactor
  • test update
  • typo fix
  • metadata update

Hey there πŸ‘‹
Thanks for this awesome library!

I discovered this player because rubyevents.org uses it.
On rubyevents.org, there is a custom implementation for setting playback speed. This is done by adding a select element to the control bar and calling the player instance setPlaybackRate method.

While this works well, there is a small issue where the select dropdown closes automatically when clicked in some browsers. There is a related issue on the rubyevents repo, here.

The problem seems to be caused by the onClickOnControlBar event listener. This listener triggers when the custom <select> element is clicked and tries to hide the control bar by focusing the container element:

// Hide controls with timer after clicks
this.player.elements.container.focus()

This focus causes the playback speed select dropdown to close prematurely.


This PR would skip the onClickOnControlBar behaviour when the click target has a v-customControlButton class.
This would allow us to add custom control elements that are independent of the default control bar functionality.
I’d love to hear your thoughts on this approach. Also, I'm also not sure if v-customControlButton is the best class name for this purpose.

@vercel
Copy link

vercel bot commented May 28, 2025

@leonvogt is attempting to deploy a commit to the Vlitejs Team on Vercel.

A member of the Team first needs to authorize it.

@yoriiis
Copy link
Member

yoriiis commented Jun 10, 2025

Hi @leonvogt, thanks for the feedback, I've read the RubyEvents issues too.

The focus change is triggered by the onClickOnControlBar function but should be tied to the selector conditions (validateTarget conditions).

I suggest encapsulating the line, this solves the problem on RubyEvents and keeps the focus on elements not observed by onClickOnControlBar.

It also fixes another problem with Vlitejs, when the subtitle button is clicked, the focus is not currently maintained.

I'll take this opportunity to update the demo, which uses an older version (v5) and doesn't reflect the latest developments in the project.

diff --git a/src/components/control-bar/control-bar.ts b/src/components/control-bar/control-bar.ts
index 2164bcb..2068c99 100644
--- a/src/components/control-bar/control-bar.ts
+++ b/src/components/control-bar/control-bar.ts
@@ -160,8 +160,10 @@ export default class ControlBar {
                        this.toggleFullscreen(e)
                }
 
+               if (validateTargetPlayPauseButton || validateTargetVolume || validateTargetFullscreen) {
+                       this.player.elements.container.focus()
+               }
                // Hide controls with timer after clicks
-               this.player.elements.container.focus()
                this.player.Vlitejs.startAutoHideTimer()
        }

@yoriiis yoriiis force-pushed the support-custom-controls-in-control-bar branch from da2a8a8 to 07fc2fe Compare June 10, 2025 19:12
@leonvogt
Copy link
Contributor Author

Hi @yoriiis, I really like your approach of encapsulating the focus change within the selector conditions! That way, library consumers don't need to do anything, which is really nice. I've updated the PR accordingly.

@yoriiis
Copy link
Member

yoriiis commented Jun 10, 2025

@leonvogt to fix lint's work, use either the VSCode workspace with auto format on save, or the npm biome:fix script

@leonvogt leonvogt force-pushed the support-custom-controls-in-control-bar branch from 686f5bc to 55fb4d4 Compare June 10, 2025 21:38
@leonvogt
Copy link
Contributor Author

@yoriiis, I've run the biome:fix script, thanks for the hint. The lint checks should be fixed now.

@vercel
Copy link

vercel bot commented Jun 11, 2025

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Updated (UTC)
vlite βœ… Ready (Inspect) Visit Preview Jun 11, 2025 8:01am

@yoriiis yoriiis merged commit a56476e into vlitejs:main Jun 11, 2025
13 checks passed
@yoriiis yoriiis changed the title Add support for custom controls in control bar Limit focus changes on control bar internal components Jun 11, 2025
@yoriiis
Copy link
Member

yoriiis commented Jun 11, 2025

Available in release 7.3.2 πŸŽ‰

@leonvogt
Copy link
Contributor Author

Thank you so much for the fast merge and release, @yoriiis!

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