✨(frontend) add SR announcements for transcript and recording
announce transcript and record events to sr to provide clear feedback Signed-off-by: Cyril <c.gromoff@gmail.com>
This commit is contained in:
committed by
aleb_the_flash
parent
394a1be322
commit
6ae68013af
@@ -1,6 +1,6 @@
|
|||||||
import { css } from '@/styled-system/css'
|
import { css } from '@/styled-system/css'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { useMemo } from 'react'
|
import { useMemo, useRef, useState, useEffect } from 'react'
|
||||||
import { Text } from '@/primitives'
|
import { Text } from '@/primitives'
|
||||||
import {
|
import {
|
||||||
RecordingMode,
|
RecordingMode,
|
||||||
@@ -21,6 +21,9 @@ export const RecordingStateToast = () => {
|
|||||||
|
|
||||||
const { openTranscript, openScreenRecording } = useSidePanel()
|
const { openTranscript, openScreenRecording } = useSidePanel()
|
||||||
|
|
||||||
|
const [srMessage, setSrMessage] = useState('')
|
||||||
|
const lastKeyRef = useRef('')
|
||||||
|
|
||||||
const hasTranscriptAccess = useHasRecordingAccess(
|
const hasTranscriptAccess = useHasRecordingAccess(
|
||||||
RecordingMode.Transcript,
|
RecordingMode.Transcript,
|
||||||
FeatureFlags.Transcript
|
FeatureFlags.Transcript
|
||||||
@@ -67,6 +70,23 @@ export const RecordingStateToast = () => {
|
|||||||
return `${metadata.recording_mode}.${status}`
|
return `${metadata.recording_mode}.${status}`
|
||||||
}, [metadata, isStarted, isStarting, isRecording])
|
}, [metadata, isStarted, isStarting, isRecording])
|
||||||
|
|
||||||
|
// Update screen reader message only when the key actually changes
|
||||||
|
// This prevents duplicate announcements caused by re-renders
|
||||||
|
useEffect(() => {
|
||||||
|
if (key && key !== lastKeyRef.current) {
|
||||||
|
lastKeyRef.current = key
|
||||||
|
const message = t(key)
|
||||||
|
setSrMessage(message)
|
||||||
|
|
||||||
|
// Clear message after 3 seconds to prevent it from being announced again
|
||||||
|
const timer = setTimeout(() => {
|
||||||
|
setSrMessage('')
|
||||||
|
}, 3000)
|
||||||
|
|
||||||
|
return () => clearTimeout(timer)
|
||||||
|
}
|
||||||
|
}, [key, t])
|
||||||
|
|
||||||
if (!key) return null
|
if (!key) return null
|
||||||
|
|
||||||
const hasScreenRecordingAccessAndActive =
|
const hasScreenRecordingAccessAndActive =
|
||||||
@@ -74,6 +94,17 @@ export const RecordingStateToast = () => {
|
|||||||
const hasTranscriptAccessAndActive = isTranscriptActive && hasTranscriptAccess
|
const hasTranscriptAccessAndActive = isTranscriptActive && hasTranscriptAccess
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<>
|
||||||
|
{/* Screen reader only message to announce state changes once */}
|
||||||
|
<div
|
||||||
|
role="status"
|
||||||
|
aria-live="polite"
|
||||||
|
aria-atomic="true"
|
||||||
|
className="sr-only"
|
||||||
|
>
|
||||||
|
{srMessage}
|
||||||
|
</div>
|
||||||
|
{/* Visual banner (without aria-live to avoid duplicate announcements) */}
|
||||||
<div
|
<div
|
||||||
className={css({
|
className={css({
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
@@ -95,7 +126,8 @@ export const RecordingStateToast = () => {
|
|||||||
isTranscriptActive={isTranscriptActive}
|
isTranscriptActive={isTranscriptActive}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{!hasScreenRecordingAccessAndActive && !hasTranscriptAccessAndActive && (
|
{!hasScreenRecordingAccessAndActive &&
|
||||||
|
!hasTranscriptAccessAndActive && (
|
||||||
<Text
|
<Text
|
||||||
variant={'sm'}
|
variant={'sm'}
|
||||||
className={css({
|
className={css({
|
||||||
@@ -130,5 +162,6 @@ export const RecordingStateToast = () => {
|
|||||||
</RACButton>
|
</RACButton>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user