diff --git a/src/oceans/components/common/Guide.jsx b/src/oceans/components/common/Guide.jsx index f17b8ffc..cc1f342c 100644 --- a/src/oceans/components/common/Guide.jsx +++ b/src/oceans/components/common/Guide.jsx @@ -29,11 +29,37 @@ export const stopTypingSounds = () => { }; let UnwrappedGuide = class Guide extends React.Component { + guideDialogRef = React.createRef(); + + componentDidUpdate() { + // Focus the dialog only when the guide changes, not on every re-render + const currentGuide = guide.getCurrentGuide(); + const currentGuideId = currentGuide ? currentGuide.id : null; + + if ( + currentGuideId !== this.lastFocusedGuideId && + currentGuide && + this.guideDialogRef && + this.guideDialogRef.current + ) { + this.guideDialogRef.current.focus(); + this.lastFocusedGuideId = currentGuideId; + } else if (!currentGuide) { + this.lastFocusedGuideId = null; + } + } onTypingDone() { clearInterval(getState().guideTypingTimer); setState({guideShowing: true, guideTypingTimer: undefined}); } + onGuideKeyDown = (e) => { + if (e.key === ' ' || e.key === 'Enter' || e.key === 'Spacebar') { + e.preventDefault(); + this.onGuideClick(); + } + }; + onGuideClick = () => { const state = getState(); const currentGuide = guide.getCurrentGuide(); @@ -157,9 +183,17 @@ let UnwrappedGuide = class Guide extends React.Component { key={currentGuide.id} style={guideBgStyle} onClick={this.onGuideClick} + onKeyDown={this.onGuideKeyDown} + tabIndex={0} + role="button" + aria-label={I18n.t('continue')} id="uitest-dismiss-guide" >