-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
Improve mute button usability #3942
Improve mute button usability #3942
Conversation
Overall this is great! Thanks for the PR! I think that there may be a way to make this a bit simpler:
I also think that we should probably make Also note that #3918 should be fixed in the current master. Can you rebase your PR on the current master when you get a chance? |
lastVolume(percentAsDecimal) { | ||
if (percentAsDecimal !== undefined) { | ||
this.lastVolume_ = percentAsDecimal; | ||
return this; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should just return
when used as setter.
* a reference to the calling player when setting and the | ||
* current volume as a percent when getting | ||
*/ | ||
volumeBeforeDrag(percentAsDecimal) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should also be marked as private
@@ -65,7 +65,15 @@ class MuteToggle extends Button { | |||
* @listens click | |||
*/ | |||
handleClick(event) { | |||
this.player_.muted(this.player_.muted() ? false : true); | |||
const vol = this.player_.volume(); | |||
const lastVolume = this.player_.lastVolume(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it possible for the lastVolume
to end up being 0? Is it worth handling? At that point, I guess would be to set the volume to 0.5?
After the changes to how lastVolume is set, dragging the VolumeBar to 0 and then clicking on the leftmost part of the volumebar would result in lastVolume being set to 0. This prevents that from happening.
651907f
to
ad8dd5d
Compare
* | ||
* @listens slideractive | ||
*/ | ||
updateLastVolume() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we probably want this function to be private (only used internally) just like Player#lastVolume_()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, @private
jsdoc directive
updateLastVolume() { | ||
const volumeBeforeDrag = this.player_.volume(); | ||
|
||
this.on('sliderinactive', function setLastVolume() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can actually use this.one('sliderinactive'
here that way you don't have to use this.off
below. I would also say that you can just use an arrow function here rather than a named one. ex:
this.one('sliderinactive', () => {
// current function goes here
});
* @return {number} | ||
* the current value of lastVolume as a percent when getting | ||
*/ | ||
lastVolume_(percentAsDecimal) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should have an @private
jsdoc directive.
* | ||
* @listens slideractive | ||
*/ | ||
updateLastVolume() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, @private
jsdoc directive
@brandonocasey @gkatsev Thanks so much for the feedback! Have addressed. |
@kevinlitchfield thanks so much for your work! |
Clicking
MuteToggle
whenvolume
is 0 now has more user-friendly behavior. Previously, clicking MuteToggle whenvolume
was 0 had no user-visible effect (as discussed in #3909, which this PR addresses).There are three possible scenarios I'm aware of for setting the volume to 0 and then dealing with a click on
MuteToggle
that need to be taken into account:VolumeBar
to 0 with mouse or finger. In this case,volume
should be restored to the level it was at when the user started draggingVolumeBar
.volume
to 0 with keyboard. In this case, clickingMuteToggle
should restore the volume to its last value before it reached 0.volume
is set directly to 0 with external JS, by a plugin, etc. In this case, it should be up to the programmer to control what level the volume should be set to when the user clicksMuteToggle
, but it should never remain at 0.How this solution works:
MuteToggle
when volume is zero setsvolume
to the value of a new property,lastVolume
.lastVolume
is updated to matchvolume
whenPlayer#volume
sets a new value forvolume
, unless the new value ofvolume
is 0.VolumeBar
,volume
is saved into another new property,volumeBeforeDrag
. When the user finishes draggingVolumeBar
, ifvolume
is 0,lastVolume
is updated to matchvolumeBeforeDrag
.Note: This should not be merged until #3918 is fixed. As explained in that bug report: