From 4d5b1ce5fdd0a6c8cbbc99fe05be0f1add2c901e Mon Sep 17 00:00:00 2001 From: Henry Heino <46334387+personalizedrefrigerator@users.noreply.github.com> Date: Sat, 9 Nov 2024 04:46:16 -0800 Subject: [PATCH] Mobile: Accessibility: Improve setting control accessibility (#11358) --- packages/app-mobile/components/Dropdown.tsx | 17 ++++++++++++++--- .../screens/ConfigScreen/SettingComponent.tsx | 16 ++++++++++++---- .../screens/ConfigScreen/SettingsToggle.tsx | 1 + 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/packages/app-mobile/components/Dropdown.tsx b/packages/app-mobile/components/Dropdown.tsx index a04cfcaaf..b18203a6c 100644 --- a/packages/app-mobile/components/Dropdown.tsx +++ b/packages/app-mobile/components/Dropdown.tsx @@ -23,6 +23,7 @@ interface DropdownProps { headerStyle?: TextStyle; itemStyle?: TextStyle; disabled?: boolean; + accessibilityHint?: string; labelTransform?: 'trim'; items: DropdownListItem[]; @@ -169,6 +170,7 @@ class Dropdown extends Component { { this.onCloseList(); @@ -209,12 +211,19 @@ class Dropdown extends Component { style={headerWrapperStyle} disabled={this.props.disabled} onPress={this.onOpenList} - role='button' + accessibilityRole='button' + accessibilityHint={[this.props.accessibilityHint, _('Opens dropdown')].join(' ')} > {headerLabel} - {'▼'} + {'▼'} {this.state.listVisible ? null : this.props.coverableChildrenRight} @@ -237,11 +246,13 @@ class Dropdown extends Component { + style={wrapperStyle} + > ({ length: itemHeight, diff --git a/packages/app-mobile/components/screens/ConfigScreen/SettingComponent.tsx b/packages/app-mobile/components/screens/ConfigScreen/SettingComponent.tsx index bb0894a64..74cd66e2b 100644 --- a/packages/app-mobile/components/screens/ConfigScreen/SettingComponent.tsx +++ b/packages/app-mobile/components/screens/ConfigScreen/SettingComponent.tsx @@ -10,6 +10,7 @@ import SettingsToggle from './SettingsToggle'; import FileSystemPathSelector from './FileSystemPathSelector'; import shim from '@joplin/lib/shim'; import { themeStyle } from '../../global-style'; +import { useId } from 'react'; interface Props { settingId: string; @@ -39,16 +40,19 @@ const SettingComponent: React.FunctionComponent = props => { const descriptionComp = !settingDescription ? null : {settingDescription}; const containerStyle = props.styles.getContainerStyle(!!settingDescription); + const labelId = useId(); + if (md.isEnum) { const value = props.value?.toString(); const items = Setting.enumOptionsToValueLabels(md.options(), md.optionsOrder ? md.optionsOrder() : []); + const label = md.label(); return ( - {md.label()} + {label} = props => { onValueChange={(itemValue: string) => { void props.updateSettingValue(props.settingId, itemValue); }} + accessibilityHint={label} /> {descriptionComp} @@ -90,6 +95,7 @@ const SettingComponent: React.FunctionComponent = props => { const unitLabel = md.unitLabel ? md.unitLabel(props.value) : props.value; const minimum = 'minimum' in md ? md.minimum : 0; const maximum = 'maximum' in md ? md.maximum : 10; + const label = md.label(); // Note: Do NOT add the minimumTrackTintColor and maximumTrackTintColor props // on the Slider as they are buggy and can crash the app on certain devices. @@ -97,8 +103,8 @@ const SettingComponent: React.FunctionComponent = props => { // https://github.com/react-native-community/react-native-slider/issues/161 return ( - - {md.label()} + + {label} {unitLabel} @@ -110,6 +116,7 @@ const SettingComponent: React.FunctionComponent = props => { maximumValue={maximum} value={props.value} onValueChange={newValue => void props.updateSettingValue(props.settingId, newValue)} + accessibilityHint={label} /> @@ -129,7 +136,7 @@ const SettingComponent: React.FunctionComponent = props => { return ( - + {md.label()} = props => { value={props.value} onChangeText={(newValue: string) => void props.updateSettingValue(props.settingId, newValue)} secureTextEntry={!!md.secure} + aria-labelledby={labelId} /> {descriptionComp} diff --git a/packages/app-mobile/components/screens/ConfigScreen/SettingsToggle.tsx b/packages/app-mobile/components/screens/ConfigScreen/SettingsToggle.tsx index 4543d5b7e..a9c4f38cf 100644 --- a/packages/app-mobile/components/screens/ConfigScreen/SettingsToggle.tsx +++ b/packages/app-mobile/components/screens/ConfigScreen/SettingsToggle.tsx @@ -36,6 +36,7 @@ const SettingsToggle: FunctionComponent = props => { trackColor={{ false: theme.dividerColor }} value={props.value} onValueChange={(value: boolean) => void props.updateSettingValue(props.settingId, value)} + accessibilityHint={props.label} /> {props.description}