Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion packages/scratch-gui/src/components/cards/cards.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import PropTypes from 'prop-types';
import React, {Fragment} from 'react';
import React, {Fragment, useRef, useEffect} from 'react';
import classNames from 'classnames';
import {FormattedMessage} from 'react-intl';
import Draggable from 'react-draggable';
Expand Down Expand Up @@ -354,6 +354,21 @@ const Cards = props => {

if (activeDeckId === null) return;

const cardRef = useRef(null);

useEffect(() => {
// Only focus if there’s an actual tutorial step (image/video)
const steps = content[activeDeckId]?.steps;
const isTutorialStep = steps?.[step]?.video;

if (isTutorialStep && cardRef.current) {
// Defer focus to next animation frame for layout stability
requestAnimationFrame(() => {
cardRef.current.focus();
});
}
}, [activeDeckId, step, content]);

// Tutorial cards need to calculate their own dragging bounds
// to allow for dragging the cards off the left, right and bottom
// edges of the workspace.
Expand Down Expand Up @@ -385,6 +400,8 @@ const Cards = props => {
top: `${menuBarHeight}px`,
left: `${-cardHorizontalDragOffset}px`
}}
ref={cardRef}
tabIndex={-1}
>
<Draggable
bounds="parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
exports[`Cards component showVideos=false shows the title image/name instead of video step 1`] = `
<div
style="width: 1824px; height: 977px; top: 48px; left: -400px;"
tabindex="-1"
>
<div
class="react-draggable"
Expand Down Expand Up @@ -51,6 +52,7 @@ exports[`Cards component showVideos=false shows the title image/name instead of
exports[`Cards component showVideos=true shows the video step 1`] = `
<div
style="width: 1824px; height: 977px; top: 48px; left: -400px;"
tabindex="-1"
>
<div
class="react-draggable"
Expand Down
Loading