From 6a5097cdc9b1efb5c01ae152d154b20431e77fd7 Mon Sep 17 00:00:00 2001 From: Galeel Bhasha Satthar Date: Tue, 24 Jul 2018 00:53:37 +0530 Subject: [PATCH] made accessibilityLabel as an optional prop, If not set by default it would use the item value. - [Galeel] --- README.md | 4 ++-- SegmentedControlTab.js | 8 +++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 7116f64..261239d 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/SegmentedControlTab.js b/SegmentedControlTab.js index 51fb602..eb3530e 100644 --- a/SegmentedControlTab.js +++ b/SegmentedControlTab.js @@ -37,7 +37,7 @@ const TabOption = ({ firstTabStyle, lastTabStyle]} accessible={accessible} - { ...(accessibilityLabel && accessibilityLabel.trim() !== '' && {accessibilityLabel: accessibilityLabel})} + accessibilityLabel={accessibilityLabel} onPress={() => onTabPress(index)} activeOpacity={1}> @@ -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 ( ); }) @@ -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,