Skip to content

Commit

Permalink
improvement: a11y RovingTabindex for loading msgs
Browse files Browse the repository at this point in the history
  • Loading branch information
WofWca committed Jan 10, 2025
1 parent f365874 commit 38e6eaf
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions packages/frontend/src/components/message/MessageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,6 @@ export const MessageListInner = React.memo(
/>
)
} else if (message?.kind === 'loadingError') {
// TODO shall we add `useRovingTabindex` here as well?
return (
<MessageLoadingError
messageId={messageId}
Expand All @@ -838,7 +837,6 @@ export const MessageListInner = React.memo(
// setTimeout tells it to call method in next event loop iteration, so after rendering
// it is debounced later so we can call it here multiple times and it's ok
setTimeout(loadMissingMessages)
// TODO shall we add `useRovingTabindex` here as well?
return <MessageLoading messageId={messageId} />
}
}
Expand Down Expand Up @@ -866,13 +864,20 @@ function MessageLoadingError({
messageId: T.MessageListItem & { kind: 'message' }
message: T.MessageLoadResult
}) {
const ref = useRef<HTMLDivElement>(null)
const rovingTabindex = useRovingTabindex(ref)

return (
<div className='info-message' id={String(messageId.msg_id)}>
<div
className='bubble'
ref={ref}
className={'bubble ' + rovingTabindex.className}
style={{
backgroundColor: 'rgba(55,0,0,0.5)',
}}
tabIndex={rovingTabindex.tabIndex}
onKeyDown={rovingTabindex.onKeydown}
onFocus={rovingTabindex.setAsActiveElement}
>
loading message {messageId.msg_id} failed: {message.error}
</div>
Expand All @@ -884,13 +889,20 @@ function MessageLoading({
}: {
messageId: T.MessageListItem & { kind: 'message' }
}) {
const ref = useRef<HTMLDivElement>(null)
const rovingTabindex = useRovingTabindex(ref)

return (
<div className='info-message' id={String(messageId.msg_id)}>
<div
className='bubble'
ref={ref}
className={'bubble ' + rovingTabindex.className}
style={{
backgroundColor: 'rgba(55,0,0,0.5)',
}}
tabIndex={rovingTabindex.tabIndex}
onKeyDown={rovingTabindex.onKeydown}
onFocus={rovingTabindex.setAsActiveElement}
>
Loading Message {messageId.msg_id}
</div>
Expand Down

0 comments on commit 38e6eaf

Please sign in to comment.