Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Announce Snackbar appearance to screen reader #437

Merged
merged 6 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@department-of-veterans-affairs/mobile-component-library",
"version": "0.21.1-alpha.9",
"version": "0.21.1-alpha.10",
"description": "VA Design System Mobile Component Library",
"main": "src/index.tsx",
"scripts": {
Expand Down
22 changes: 17 additions & 5 deletions packages/components/src/components/Snackbar/Snackbar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
AccessibilityInfo,
Pressable,
PressableStateCallbackType,
Text,
Expand All @@ -11,7 +12,7 @@ import {
} from 'react-native'
import { ToastProps } from 'react-native-toast-notifications/lib/typescript/toast'
import { useTranslation } from 'react-i18next'
import React, { FC } from 'react'
import React, { FC, useEffect } from 'react'

import { Icon, IconProps } from '../Icon/Icon'
import { Spacer } from '../Spacer/Spacer'
Expand Down Expand Up @@ -74,7 +75,10 @@ const SnackbarButton: FC<SnackbarButtonProps> = ({ text, onPress }) => {
)
}

export type SnackbarProps = Omit<ToastProps, 'data'> & snackbarData
export type SnackbarProps = Omit<ToastProps, 'data' | 'message'> &
snackbarData & {
message: string
}

/**
* To use SnackbarProvider, import SnackbarProvider in App.tsx (or similar foundational file) and
Expand Down Expand Up @@ -106,10 +110,18 @@ export const Snackbar: FC<SnackbarProps> = (toast) => {
const fontScale = useWindowDimensions().fontScale
const theme = useTheme()
const { t } = useTranslation()
// const a11yAnnounce =
// AccessibilityInfo.announceForAccessibility('Test announce two')

// useEffect(() => a11yAnnounce, [a11yAnnounce])
/**
* useEffect to handle announcing the Snackbar appearing to the screen reader
*/
useEffect(() => {
// Delay to prevent iOS from instantly refocusing the action prompting the Snackbar if synchronous
setTimeout(
() => AccessibilityInfo.announceForAccessibility(messageA11y || toast.message),
50,
)
// Empty dependency array so useEffect only runs on initial render
}, [])

const helperText: TextStyle = {
fontFamily: 'SourceSansPro-Regular',
Expand Down
Loading