1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Prevent Focus Loss When Skip Button is Pressed (#6413)

* Prevent Focus Loss When Skip Button is Pressed

* Implement the suggested changes

* Update index.js

* Ensures focus shifts to the pause button

* Apply suggested changes

---------

Co-authored-by: rlauu <46294892+rlauu@users.noreply.github.com>
This commit is contained in:
rlauuzo 2025-01-13 16:55:08 +01:00 committed by GitHub
parent 700e72b409
commit 4f17cebc02
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 41 additions and 16 deletions

View file

@ -93,6 +93,7 @@ function isCurrentlyFocusableInternal(elem) {
// Determines if a focusable element can be focused at a given point in time // Determines if a focusable element can be focused at a given point in time
function isCurrentlyFocusable(elem) { function isCurrentlyFocusable(elem) {
if (!elem.classList?.contains('focusable')) {
if (elem.disabled) { if (elem.disabled) {
return false; return false;
} }
@ -110,6 +111,7 @@ function isCurrentlyFocusable(elem) {
return false; return false;
} }
} }
}
return isCurrentlyFocusableInternal(elem); return isCurrentlyFocusableInternal(elem);
} }

View file

@ -20,6 +20,15 @@ interface ShowOptions {
function onHideComplete(this: HTMLButtonElement) { function onHideComplete(this: HTMLButtonElement) {
if (this) { if (this) {
// Handle focus after the hide transition completes
if (document.activeElement === this) {
this.blur();
const pauseButton = document.querySelector('.btnPause');
if (pauseButton && focusManager.isCurrentlyFocusable(pauseButton)) {
focusManager.focus(pauseButton);
}
}
this.classList.add('hide'); this.classList.add('hide');
} }
} }

View file

@ -304,11 +304,15 @@ export default function (view) {
} }
function slideDownToShow(elem) { function slideDownToShow(elem) {
clearHideAnimationEventListeners(elem);
elem.classList.remove('hide');
elem.classList.remove('osdHeader-hidden'); elem.classList.remove('osdHeader-hidden');
} }
function slideUpToHide(elem) { function slideUpToHide(elem) {
clearHideAnimationEventListeners(elem);
elem.classList.add('osdHeader-hidden'); elem.classList.add('osdHeader-hidden');
elem.addEventListener(transitionEndEventName, onHideAnimationComplete);
} }
function clearHideAnimationEventListeners(elem) { function clearHideAnimationEventListeners(elem) {
@ -317,7 +321,7 @@ export default function (view) {
function onHideAnimationComplete(e) { function onHideAnimationComplete(e) {
const elem = e.target; const elem = e.target;
if (elem != osdBottomElement) return; if (elem !== osdBottomElement && elem !== headerElement) return;
elem.classList.add('hide'); elem.classList.add('hide');
elem.removeEventListener(transitionEndEventName, onHideAnimationComplete); elem.removeEventListener(transitionEndEventName, onHideAnimationComplete);
} }
@ -338,8 +342,17 @@ export default function (view) {
_focus(focusElement); _focus(focusElement);
} }
toggleSubtitleSync(); toggleSubtitleSync();
} else if (currentVisibleMenu === 'osd' && focusElement && !layoutManager.mobile) { } else if (currentVisibleMenu === 'osd' && !layoutManager.mobile) {
_focus(focusElement); // If no focus element is provided, try to keep current focus if it's valid,
// otherwise default to pause button
if (!focusElement) {
const currentFocus = document.activeElement;
if (!currentFocus || !focusManager.isCurrentlyFocusable(currentFocus)) {
focusElement = osdBottomElement.querySelector('.btnPause');
}
}
if (focusElement) _focus(focusElement);
} }
} }
@ -354,7 +367,8 @@ export default function (view) {
toggleSubtitleSync('hide'); toggleSubtitleSync('hide');
// Firefox does not blur by itself // Firefox does not blur by itself
if (document.activeElement) { if (osdBottomElement.contains(document.activeElement)
|| headerElement.contains(document.activeElement)) {
document.activeElement.blur(); document.activeElement.blur();
} }
} }