fix(a11y): add initial focus to play button in speaking modal (#66419)

This commit is contained in:
Huyen Nguyen
2026-03-24 17:44:54 +07:00
committed by GitHub
parent ca05f09f30
commit a0f37ae009
2 changed files with 13 additions and 6 deletions

View File

@@ -151,6 +151,7 @@ const SpeakingModal = ({
useState<ComparisonResult | null>(null);
const [hasStartedRecording, setHasStartedRecording] = useState(false);
const [previouslyListening, setPreviouslyListening] = useState(false);
const playButtonRef = useRef<HTMLButtonElement | null>(null);
const audioRef = useRef<HTMLAudioElement | null>(null);
const stopListeningTimeoutRef = useRef<
ReturnType<typeof setTimeout> | undefined
@@ -311,7 +312,12 @@ const SpeakingModal = ({
};
return (
<Modal onClose={closeSpeakingModal} open={isSpeakingModalOpen} size='large'>
<Modal
onClose={closeSpeakingModal}
open={isSpeakingModalOpen}
size='large'
initialFocus={playButtonRef}
>
<Modal.Header closeButtonClassNames='close'>
{t('speaking-modal.heading')}
</Modal.Header>
@@ -323,6 +329,7 @@ const SpeakingModal = ({
{sentence}
</p>
<Button
ref={playButtonRef}
size='medium'
onClick={() => void handlePlay()}
aria-describedby='speaking-sentence'

View File

@@ -47,11 +47,11 @@ test.describe('Multiple Choice Question Challenge - With Speaking Modal', () =>
await expect(page.getByRole('dialog')).toBeVisible();
await expect(
page.getByRole('button', {
name: translations['speaking-modal']['play']
})
).toBeVisible();
const playButton = page.getByRole('button', {
name: translations['speaking-modal']['play']
});
await expect(playButton).toBeVisible();
await expect(playButton).toBeFocused(); // The button is focused by default
await expect(
page.getByRole('button', {
name: translations['speaking-modal']['record']