fix(app): card retry keeps focus and voice when no retry is left
A retry ending on a failure with no retry (network to integrity, engine stopped for good) keeps the polite region and moves focus to Consulter. Busy look on Réessayer, error tone once the engine stopped, one attempt for two calls in one tick; tests for the stopped engine, two core cards and no blob URL after unmount.
This commit is contained in:
1 parent
4a7919c763
commit
b378cf066f
4 files changed
+97
-15
No files matched your search
@@ -26,27 +26,30 @@ export interface CardFailureProps {
|
||||
|
||||
/**
|
||||
* A catalogue card's failure (board 30, R-1 to R-4): the line (not a live
|
||||
* region, so several cards failing at load stay quiet), « Réessayer » where a
|
||||
* retry can work, and a polite region that says the line again only after a
|
||||
* retry failed (empty at load and while an attempt runs).
|
||||
* region, so several cards failing at load stay quiet), in the warning tone
|
||||
* where « Réessayer » can work and the error tone where it cannot (a refused
|
||||
* version, the engine stopped for good), and a polite region that says the
|
||||
* line again only after a retry failed (empty at load and while an attempt
|
||||
* runs). The region stays once a retry ran, even when the new failure offers
|
||||
* no retry, so the line it ends on is still said.
|
||||
*/
|
||||
export default function CardFailure({ failed, onRetry, retryRef, children }: CardFailureProps) {
|
||||
const t = useT()
|
||||
const stopped = useCoreStopped()
|
||||
const { failure, retrying, attempt } = failed
|
||||
const { integrity, refused, retry } = cardFailure(failure, stopped)
|
||||
const { integrity, retry } = cardFailure(failure, stopped)
|
||||
const text = failureText(t, failure, integrity)
|
||||
|
||||
return (
|
||||
<>
|
||||
<Notice
|
||||
tone={refused ? 'error' : 'warning'}
|
||||
tone={retry ? 'warning' : 'error'}
|
||||
icon={failure === 'network' ? 'wifi-off' : 'alert'}
|
||||
live={false}
|
||||
>
|
||||
{integrity ? <strong className="font-semibold">{text}</strong> : text}
|
||||
</Notice>
|
||||
{retry && (
|
||||
{(retry || attempt > 0) && (
|
||||
<div aria-live="polite" className="sr-only">
|
||||
{!retrying && attempt > 0 ? text : ''}
|
||||
</div>
|
||||
@@ -57,7 +60,7 @@ export default function CardFailure({ failed, onRetry, retryRef, children }: Car
|
||||
ref={retryRef}
|
||||
type="button"
|
||||
variant="secondary"
|
||||
className="min-h-11"
|
||||
className="min-h-11 aria-disabled:cursor-wait aria-disabled:opacity-60"
|
||||
aria-disabled={retrying ? 'true' : undefined}
|
||||
onClick={onRetry}
|
||||
>
|
||||
|
||||
@@ -56,8 +56,10 @@ function ConsultLink({ sheetId, name }: { sheetId: string; name: string }) {
|
||||
}
|
||||
|
||||
/**
|
||||
* After a successful retry, the focus left on the removed « Réessayer » (or on
|
||||
* nothing) moves to the card's « Consulter » (R-3); focus elsewhere is kept.
|
||||
* When a retry settles without its « Réessayer » (success, or a failure with no
|
||||
* retry left), the focus left on the removed button (or on nothing) moves to
|
||||
* the card's « Consulter » (R-3); focus elsewhere, or on a « Réessayer » still
|
||||
* there, is kept.
|
||||
*/
|
||||
function useFocusAfterRetry(state: CardState) {
|
||||
const item = useRef<HTMLLIElement>(null)
|
||||
@@ -65,11 +67,17 @@ function useFocusAfterRetry(state: CardState) {
|
||||
const wasRetrying = useRef(false)
|
||||
|
||||
useEffect(() => {
|
||||
if (state.status === 'failed') wasRetrying.current = state.retrying
|
||||
if (state.status !== 'ready' || !wasRetrying.current) return
|
||||
if (state.status === 'loading') return
|
||||
if (state.status === 'failed' && state.retrying) {
|
||||
wasRetrying.current = true
|
||||
return
|
||||
}
|
||||
if (!wasRetrying.current) return
|
||||
wasRetrying.current = false
|
||||
const button = lastRetry.current
|
||||
if (button?.isConnected) return
|
||||
const active = document.activeElement
|
||||
if (!active || active === document.body || active === lastRetry.current) {
|
||||
if (!active || active === document.body || active === button) {
|
||||
item.current?.querySelector('a')?.focus()
|
||||
}
|
||||
}, [state])
|
||||
|
||||
Reference in new issue
Block a user