Skip to content

Commit 54c7c6c

Browse files
authored
Merge pull request #579 from adzhindzhi/task/uepr-477-tips-library-return-focus-inconsistency-fix
[UEPR-477] Focus video on tutorial library choice with keyboard
2 parents 58bfd6f + 184ac49 commit 54c7c6c

2 files changed

Lines changed: 19 additions & 20 deletions

File tree

packages/scratch-gui/src/components/cards/cards.jsx

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import PropTypes from 'prop-types';
2-
import React, {Fragment, useRef, useEffect} from 'react';
2+
import React, {Fragment} from 'react';
33
import classNames from 'classnames';
44
import {FormattedMessage} from 'react-intl';
55
import Draggable from 'react-draggable';
@@ -99,6 +99,20 @@ class VideoStep extends React.Component {
9999
script2.async = true;
100100
script2.setAttribute('id', 'wistia-video-api');
101101
document.body.appendChild(script2);
102+
103+
// The Wistia API doesn't provide a callback for when the video is ready,
104+
// so we use the global _wq queue that Wistia provides for this purpose.
105+
// See the below for more details.
106+
// https://docs.wistia.com/docs/javascript-player-api#with-standard-embeds
107+
window._wq = window._wq || [];
108+
window._wq.push({
109+
id: this.props.video,
110+
onReady: video => {
111+
if (video) {
112+
video.focus();
113+
}
114+
}});
115+
102116
}
103117

104118
// We use the Wistia API here to update or pause the video dynamically:
@@ -127,6 +141,10 @@ class VideoStep extends React.Component {
127141

128142
const script2 = document.getElementById('wistia-video-api');
129143
script2.parentNode.removeChild(script2);
144+
145+
// Clean up the _wq queue to prevent old callbacks from firing
146+
// if the component is unmounted before the video is ready
147+
window._wq = window._wq.filter(video => video.id !== this.props.video);
130148
}
131149

132150
render () {
@@ -354,21 +372,6 @@ const Cards = props => {
354372

355373
if (activeDeckId === null) return;
356374

357-
const cardRef = useRef(null);
358-
359-
useEffect(() => {
360-
// Only focus if there’s an actual tutorial step (image/video)
361-
const steps = content[activeDeckId]?.steps;
362-
const isTutorialStep = steps?.[step]?.video;
363-
364-
if (isTutorialStep && cardRef.current) {
365-
// Defer focus to next animation frame for layout stability
366-
requestAnimationFrame(() => {
367-
cardRef.current.focus();
368-
});
369-
}
370-
}, [activeDeckId, step, content]);
371-
372375
// Tutorial cards need to calculate their own dragging bounds
373376
// to allow for dragging the cards off the left, right and bottom
374377
// edges of the workspace.
@@ -400,8 +403,6 @@ const Cards = props => {
400403
top: `${menuBarHeight}px`,
401404
left: `${-cardHorizontalDragOffset}px`
402405
}}
403-
ref={cardRef}
404-
tabIndex={-1}
405406
>
406407
<Draggable
407408
bounds="parent"

packages/scratch-gui/test/unit/components/__snapshots__/cards.test.jsx.snap

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
exports[`Cards component showVideos=false shows the title image/name instead of video step 1`] = `
44
<div
55
style="width: 1824px; height: 977px; top: 48px; left: -400px;"
6-
tabindex="-1"
76
>
87
<div
98
class="react-draggable"
@@ -52,7 +51,6 @@ exports[`Cards component showVideos=false shows the title image/name instead of
5251
exports[`Cards component showVideos=true shows the video step 1`] = `
5352
<div
5453
style="width: 1824px; height: 977px; top: 48px; left: -400px;"
55-
tabindex="-1"
5654
>
5755
<div
5856
class="react-draggable"

0 commit comments

Comments
 (0)