Skip to content

Commit 2bcb44a

Browse files
committed
announce timer
1 parent 57b6a29 commit 2bcb44a

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/components/BaseTimer.vue

+13-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
getIntervalTypeColor,
77
getMinutes,
88
getSeconds,
9+
toSpacedString,
910
} from '@/utils';
1011
import { IntervalType } from '@/types';
1112
@@ -16,20 +17,28 @@ const { type, duration } = defineProps({
1617
1718
const time = computed(() => formatTime(duration));
1819
const label = computed(() => {
19-
const mins = getMinutes(duration);
20+
let mins = getMinutes(duration);
2021
const secs = getSeconds(duration);
21-
return `${mins} minutes ${secs ? secs + ' seconds ' : ''}left`;
22+
if (mins === 0 && secs === 0) {
23+
return `${toSpacedString(type)}: time out`;
24+
}
25+
if (mins === 0) {
26+
return `${toSpacedString(type)}: less than 1 minute left`;
27+
}
28+
return `${toSpacedString(type)}: ${mins + 1} minutes left`;
2229
});
2330
2431
const classes = computed(() => getIntervalTypeColor(type as IntervalType));
2532
</script>
2633
<template>
2734
<div
2835
role="timer"
36+
aria-live="polite"
37+
aria-atomic="true"
2938
class="rounded-lg border-4 px-8 py-4 text-4xl tabular-nums"
3039
:class="classes"
31-
:aria-label="label"
3240
>
33-
{{ time }}
41+
<span aria-hidden="true">{{ time }}</span>
42+
<span class="sr-only">{{ label }}</span>
3443
</div>
3544
</template>

0 commit comments

Comments
 (0)