Skip to content

Commit 2fe7c72

Browse files
Merge pull request #63 from ThakurBallary/feat/a11y
accessibility enhancement
2 parents 401b1d7 + 4343411 commit 2fe7c72

File tree

4 files changed

+21
-15
lines changed

4 files changed

+21
-15
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ export default function App() {
101101
#### RadioButton
102102
Key | Type | Required | Default | Valid Values
103103
--- | --- | --- | --- | ---
104+
accessibilityLabel | string | no | radio button | any string
104105
borderColor | string | no | color | css color formats
105106
borderSize | number | 2 | | positive numbers
106107
color | string | no | #444 | css color formats
@@ -121,6 +122,7 @@ value | string | no | | any string
121122
#### RadioGroup
122123
Key | Type | Required | Default | Valid Values
123124
--- | --- | --- | --- | ---
125+
accessibilityLabel | string | no | radio group | any string
124126
containerStyle | object | no | | react style
125127
layout | enum | no | column | row / column
126128
onPress | function | no | | any function

lib/RadioButton.tsx

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { PixelRatio, Pressable, StyleSheet, Text, View } from 'react-native';
44
import { RadioButtonProps } from './types';
55

66
export default function RadioButton({
7-
accessibilityLabel,
7+
accessibilityLabel = 'radio button',
88
borderColor,
99
borderSize = 2,
1010
color = '#444',
@@ -34,31 +34,27 @@ export default function RadioButton({
3434
}
3535

3636
function handlePress() {
37-
if (disabled) {
38-
return null;
39-
}
40-
if (onPress) {
37+
if(onPress) {
4138
onPress(id);
4239
}
43-
return null;
4440
}
4541

4642
return (
4743
<>
4844
<Pressable
45+
accessibilityHint={description}
46+
accessibilityLabel={label || accessibilityLabel}
47+
accessibilityRole="radio"
48+
accessibilityState={{ checked: selected, disabled }}
49+
disabled={disabled}
4950
onPress={handlePress}
5051
style={[
5152
styles.container,
5253
orientation,
5354
{ opacity: disabled ? 0.2 : 1 },
5455
containerStyle,
5556
]}
56-
disabled={disabled}
5757
testID={testID}
58-
accessibilityRole="radio"
59-
accessibilityLabel={label || accessibilityLabel}
60-
accessibilityHint={description}
61-
accessibilityState={{ checked: selected, disabled }}
6258
>
6359
<View
6460
style={[

lib/RadioGroup.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@ import { StyleSheet, View } from 'react-native';
44
import RadioButton from './RadioButton';
55
import { RadioGroupProps } from './types';
66

7-
export default function RadioGroup({ accessibilityLabel, containerStyle, layout = 'column', onPress, radioButtons, selectedId, testID}: RadioGroupProps) {
7+
export default function RadioGroup({
8+
accessibilityLabel = 'radio group',
9+
containerStyle,
10+
layout = 'column',
11+
onPress,
12+
radioButtons,
13+
selectedId,
14+
testID
15+
}: RadioGroupProps) {
816

917
function handlePress(id: string) {
1018
if(id !== selectedId && onPress) {
@@ -14,10 +22,10 @@ export default function RadioGroup({ accessibilityLabel, containerStyle, layout
1422

1523
return (
1624
<View
17-
style={[styles.container, { flexDirection: layout }, containerStyle]}
18-
testID={testID}
1925
accessibilityLabel={accessibilityLabel}
2026
accessibilityRole="radiogroup"
27+
style={[styles.container, { flexDirection: layout }, containerStyle]}
28+
testID={testID}
2129
>
2230
{radioButtons.map((button) => (
2331
<RadioButton

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-radio-buttons-group",
3-
"version": "3.0.3",
3+
"version": "3.0.4",
44
"description": "Simple and Best. An easy to use radio buttons for react native apps.",
55
"main": "./lib/index.ts",
66
"scripts": {

0 commit comments

Comments
 (0)