fix: announce "loading more" with aria-live=polite after delay (#2240)

This commit is contained in:
Nolan Lawson 2022-11-24 11:02:17 -08:00 committed by GitHub
parent bc664e5ca1
commit b50b9dc40b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -65,11 +65,30 @@
} }
</style> </style>
<script> <script>
import { observe } from 'svelte-extras'
import LoadingSpinner from '../LoadingSpinner.html' import LoadingSpinner from '../LoadingSpinner.html'
import { store } from '../../_store/store.js' import { store } from '../../_store/store.js'
import { fetchMoreItemsAtBottomOfTimeline } from '../../_actions/timeline.js' import { fetchMoreItemsAtBottomOfTimeline } from '../../_actions/timeline.js'
import { announceAriaLivePolite } from '../../_utils/announceAriaLivePolite.js'
const SCREEN_READER_ANNOUNCE_DELAY = 1000 // 1 second
export default { export default {
oncreate () {
// If the new statuses are delayed a significant amount of time, announce to screen readers that we're loading
let delayedAriaAnnouncementHandle
this.observe('showLoading', showLoading => {
if (showLoading) {
delayedAriaAnnouncementHandle = setTimeout(() => {
delayedAriaAnnouncementHandle = undefined
announceAriaLivePolite('intl.loadingMore')
}, SCREEN_READER_ANNOUNCE_DELAY)
} else if (delayedAriaAnnouncementHandle) {
clearTimeout(delayedAriaAnnouncementHandle)
}
})
},
store: () => store, store: () => store,
computed: { computed: {
shown: ({ $timelineInitialized, $runningUpdate, $disableInfiniteScroll }) => ( shown: ({ $timelineInitialized, $runningUpdate, $disableInfiniteScroll }) => (
@ -79,6 +98,7 @@
showLoadButton: ({ $runningUpdate, $disableInfiniteScroll }) => !$runningUpdate && $disableInfiniteScroll showLoadButton: ({ $runningUpdate, $disableInfiniteScroll }) => !$runningUpdate && $disableInfiniteScroll
}, },
methods: { methods: {
observe,
onClickLoadMore (e) { onClickLoadMore (e) {
e.preventDefault() e.preventDefault()
e.stopPropagation() e.stopPropagation()