@@ -34,12 +34,17 @@ const PickerItem = props => {
34
34
const itemValue = ! migrate && _ . isPlainObject ( value ) ? value ?. value : value ;
35
35
const isSelected = isItemSelected ( itemValue , context . value ) ;
36
36
const itemLabel = getItemLabel ( label , value , props . getItemLabel || context . getItemLabel ) ;
37
+ const selectedCounter = context . selectionLimit && context . value ?. length ;
37
38
const accessibilityProps = {
38
39
accessibilityState : isSelected ? { selected : true } : undefined ,
39
40
accessibilityHint : 'Double click to select this suggestion' ,
40
41
...Modifiers . extractAccessibilityProps ( props )
41
42
} ;
42
43
44
+ const isItemDisabled = useMemo ( ( ) => {
45
+ return disabled || ( ! isSelected && context . selectionLimit && context . selectionLimit === selectedCounter ) ;
46
+ } , [ selectedCounter ] ) ;
47
+
43
48
useEffect ( ( ) => {
44
49
if ( _ . isPlainObject ( value ) ) {
45
50
LogService . warn ( 'UILib Picker.Item will stop supporting passing object as value & label (e.g {value, label}) in the next major version. Please pass separate label and value props' ) ;
@@ -48,9 +53,9 @@ const PickerItem = props => {
48
53
49
54
const selectedIndicator = useMemo ( ( ) => {
50
55
if ( isSelected ) {
51
- return < Image source = { selectedIcon } tintColor = { disabled ? Colors . dark60 : selectedIconColor } /> ;
56
+ return < Image source = { selectedIcon } tintColor = { isItemDisabled ? Colors . dark60 : selectedIconColor } /> ;
52
57
}
53
- } , [ isSelected , disabled , selectedIcon , selectedIconColor ] ) ;
58
+ } , [ isSelected , isItemDisabled , selectedIcon , selectedIconColor ] ) ;
54
59
55
60
const _onPress = useCallback ( ( ) => {
56
61
if ( migrate ) {
@@ -67,7 +72,7 @@ const PickerItem = props => {
67
72
const _renderItem = ( ) => {
68
73
return (
69
74
< View style = { styles . container } flex row spread centerV >
70
- < Text numberOfLines = { 1 } style = { [ styles . labelText , disabled && styles . labelTextDisabled ] } >
75
+ < Text numberOfLines = { 1 } style = { [ styles . labelText , isItemDisabled && styles . labelTextDisabled ] } >
71
76
{ itemLabel }
72
77
</ Text >
73
78
{ selectedIndicator }
@@ -84,7 +89,7 @@ const PickerItem = props => {
84
89
activeOpacity = { 0.5 }
85
90
onPress = { _onPress }
86
91
onLayout = { isSelected ? onSelectedLayout : undefined }
87
- disabled = { disabled }
92
+ disabled = { isItemDisabled }
88
93
testID = { testID }
89
94
throttleTime = { 0 }
90
95
{ ...accessibilityProps }
0 commit comments