made accessibilityLabel as an optional prop, If not set by default it would use the item value. - [Galeel]

This commit is contained in:
Galeel Bhasha Satthar
2018-07-24 00:53:37 +05:30
parent d422efe379
commit 6a5097cdc9
2 changed files with 5 additions and 7 deletions

View File

@@ -83,8 +83,8 @@ activeTabBadgeStyle | external style can be passed to override the default style
onTabPress | call-back function when a tab is selected | () => {} | func
allowFontScaling | whether the segment & badge text should allow font scaling (default matches React Native default) | true | bool
accessible | enables accessibility for each tab | true | bool
accessibilityLabel | Reads out the text on each tab press when voice over is enabled and setValuesAsAccessibilityLabel prop is set to false | ['Label 1', 'Label 2', 'Label 3'] | array
setValuesAsAccessibilityLabel | uses the text passed in as values in props in place of accessibilityLabel. To have customized accessibility label mark this prop as false and set the values in accessibilityLabel prop | true | bool
accessibilityLabel | Reads out the given text on each tab press when voice over is enabled. If not set, uses the text passed in as values in props as a fallback | ['Label 1', 'Label 2', 'Label 3'] | array
## Custom styling
```javascript

View File

@@ -37,7 +37,7 @@ const TabOption = ({
firstTabStyle,
lastTabStyle]}
accessible={accessible}
{ ...(accessibilityLabel && accessibilityLabel.trim() !== '' && {accessibilityLabel: accessibilityLabel})}
accessibilityLabel={accessibilityLabel}
onPress={() => onTabPress(index)}
activeOpacity={1}>
<View style={{ flexDirection: "row" }}>
@@ -85,7 +85,6 @@ const SegmentedControlTab = ({
allowFontScaling,
accessible,
accessibilityLabel,
setValuesAsAccessibilityLabel
}) => {
const firstTabStyle = [{ borderRightWidth: values.length == 2 ? 1 : 0, borderTopLeftRadius: borderRadius, borderBottomLeftRadius: borderRadius }]
@@ -97,6 +96,7 @@ const SegmentedControlTab = ({
removeClippedSubviews={false}>
{
values.map((item, index) => {
const accessibilityText = getAccessibilityLabelByIndex(accessibilityLabel, index)
return (
<TabOption
key={index}
@@ -118,7 +118,7 @@ const SegmentedControlTab = ({
activeTabBadgeStyle={activeTabBadgeStyle}
allowFontScaling={allowFontScaling}
accessible={accessible}
accessibilityLabel={setValuesAsAccessibilityLabel ? item : getAccessibilityLabelByIndex(accessibilityLabel, index) }
accessibilityLabel={accessibilityText ? accessibilityText : item }
/>
);
})
@@ -148,14 +148,12 @@ SegmentedControlTab.propTypes = {
allowFontScaling: PropTypes.bool,
accessible: PropTypes.bool,
accessibilityLabel: PropTypes.array,
setValuesAsAccessibilityLabel: PropTypes.bool,
};
SegmentedControlTab.defaultProps = {
values: ['One', 'Two', 'Three'],
accessible: true,
accessibilityLabel: ['', '', ''],
setValuesAsAccessibilityLabel: true,
badges: ['', '', ''],
multiple: false,
selectedIndex: 0,