mirror of
https://github.com/zhigang1992/react-native-segmented-control-tab.git
synced 2026-01-12 22:50:51 +08:00
made accessibilityLabel as an optional prop, If not set by default it would use the item value. - [Galeel]
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user