@@ -107,7 +107,7 @@ class Select extends React.Component {
107
107
...selectedOptions ,
108
108
selectedOption ,
109
109
] ;
110
- if ( selectedOptions . length === options . length ) {
110
+ if ( newSelectedOptions . length === options . length ) {
111
111
newSelectedOptions = [ {
112
112
label : 'Select all' ,
113
113
value : 'selectAll' ,
@@ -128,7 +128,7 @@ class Select extends React.Component {
128
128
}
129
129
130
130
getDefaultSelected = ( props , context ) => {
131
- const { name, defaultSelected } = props ;
131
+ const { name, defaultSelected, options } = props ;
132
132
const { formik } = context ;
133
133
let defaultSelectedOptions = [ ] ;
134
134
@@ -137,14 +137,32 @@ class Select extends React.Component {
137
137
} else if ( defaultSelected === 'selectAll' ) {
138
138
defaultSelectedOptions = this . makeOptions ( ) ;
139
139
} else if ( defaultSelected != null ) {
140
- defaultSelectedOptions = Array . isArray ( defaultSelected )
141
- ? defaultSelectedOptions . concat ( defaultSelected . map ( this . remakeOption ) )
142
- : defaultSelectedOptions . concat ( this . remakeOption ( defaultSelected ) ) ;
140
+ if ( Array . isArray ( defaultSelected ) ) {
141
+ defaultSelectedOptions = defaultSelectedOptions
142
+ . concat ( defaultSelected . map ( this . remakeOption ) ) ;
143
+ if ( defaultSelectedOptions . length === options . length ) {
144
+ defaultSelectedOptions = [ {
145
+ label : 'Select all' ,
146
+ value : 'selectAll' ,
147
+ } ] . concat ( defaultSelectedOptions ) ;
148
+ }
149
+ } else {
150
+ defaultSelectedOptions = defaultSelectedOptions . concat ( this . remakeOption ( defaultSelected ) ) ;
151
+ }
143
152
} else if ( formik && name && getIn ( formik . values , name ) != null ) {
144
153
const formikValues = getIn ( formik . values , name ) ;
145
- defaultSelectedOptions = Array . isArray ( formikValues )
146
- ? defaultSelectedOptions . concat ( formikValues . map ( this . remakeOption ) )
147
- : defaultSelectedOptions . concat ( this . remakeOption ( formikValues ) ) ;
154
+ if ( Array . isArray ( formikValues ) ) {
155
+ defaultSelectedOptions = defaultSelectedOptions
156
+ . concat ( formikValues . map ( this . remakeOption ) ) ;
157
+ if ( defaultSelectedOptions . length === options . length ) {
158
+ defaultSelectedOptions = [ {
159
+ label : 'Select all' ,
160
+ value : 'selectAll' ,
161
+ } ] . concat ( defaultSelectedOptions ) ;
162
+ }
163
+ } else {
164
+ defaultSelectedOptions = defaultSelectedOptions . concat ( this . remakeOption ( formikValues ) ) ;
165
+ }
148
166
}
149
167
150
168
return defaultSelectedOptions ;
0 commit comments