Skip to content

Commit

Permalink
fix(player): manage focus when default audio layout transitions
Browse files Browse the repository at this point in the history
  • Loading branch information
mihar-22 committed Jan 25, 2024
1 parent 1d32867 commit 87340eb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ function DefaultAudioTitle() {
$chapterTitle = $isContinued ? chapterTitle : '',
isTransitionActive = useTransitionActive(rootEl);

React.useEffect(() => {
if (isTransitionActive && document.activeElement === document.body) {
media.player.el?.focus();
}
}, []);

const onResize = React.useCallback(() => {
const el = rootEl,
isOverflowing = !!el && !isTransitionActive && el.clientWidth < el.children[0]!.clientWidth;
Expand Down
3 changes: 2 additions & 1 deletion packages/vidstack/src/core/keyboard/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export const MEDIA_KEY_SHORTCUTS: MediaKeyShortcuts = {

const MODIFIER_KEYS = new Set(['Shift', 'Alt', 'Meta', 'Control']),
BUTTON_SELECTORS = 'button, [role="button"]',
IGNORE_SELECTORS = 'input, textarea, select, [contenteditable], [role^="menuitem"]';
IGNORE_SELECTORS =
'input, textarea, select, [contenteditable], [role^="menuitem"], [role="timer"]';

export class MediaKeyboardController extends MediaPlayerController {
constructor(private _media: MediaContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { ref } from 'lit-html/directives/ref.js';
import { effect, signal } from 'maverick.js';
import { toggleClass } from 'maverick.js/std';

import { watchCueTextChange } from '../../../..';
import { useDefaultLayoutContext } from '../../../../components/layouts/default/context';
import { i18n } from '../../../../components/layouts/default/translations';
import { useMediaContext, useMediaState } from '../../../../core/api/media-context';
Expand Down Expand Up @@ -67,6 +66,12 @@ function DefaultAudioTitle() {
return `${i18n(translations, word)}: ${title()}`;
};

effect(() => {
if ($isTransitionActive() && document.activeElement === document.body) {
media.player.el?.focus();
}
});

function onResize() {
const el = $ref(),
isOverflowing =
Expand Down

0 comments on commit 87340eb

Please sign in to comment.