@@ -68,7 +68,7 @@ type ComboboxOptionDataRef<T> = MutableRefObject<{
68
68
} >
69
69
70
70
interface StateDefinition < T > {
71
- dataRef : MutableRefObject < _Data >
71
+ dataRef : MutableRefObject < _Data | null >
72
72
labelId : string | null
73
73
74
74
comboboxState : ComboboxState
@@ -139,30 +139,33 @@ let reducers: {
139
139
) => StateDefinition < T >
140
140
} = {
141
141
[ ActionTypes . CloseCombobox ] ( state ) {
142
- if ( state . dataRef . current . disabled ) return state
142
+ if ( state . dataRef . current ? .disabled ) return state
143
143
if ( state . comboboxState === ComboboxState . Closed ) return state
144
144
return { ...state , activeOptionIndex : null , comboboxState : ComboboxState . Closed }
145
145
} ,
146
146
[ ActionTypes . OpenCombobox ] ( state ) {
147
- if ( state . dataRef . current . disabled ) return state
147
+ if ( state . dataRef . current ? .disabled ) return state
148
148
if ( state . comboboxState === ComboboxState . Open ) return state
149
149
150
150
// Check if we have a selected value that we can make active
151
151
let activeOptionIndex = state . activeOptionIndex
152
- let { isSelected } = state . dataRef . current
153
- let optionIdx = state . options . findIndex ( ( option ) => isSelected ( option . dataRef . current . value ) )
154
152
155
- if ( optionIdx !== - 1 ) {
156
- activeOptionIndex = optionIdx
153
+ if ( state . dataRef . current ) {
154
+ let { isSelected } = state . dataRef . current
155
+ let optionIdx = state . options . findIndex ( ( option ) => isSelected ( option . dataRef . current . value ) )
156
+
157
+ if ( optionIdx !== - 1 ) {
158
+ activeOptionIndex = optionIdx
159
+ }
157
160
}
158
161
159
162
return { ...state , comboboxState : ComboboxState . Open , activeOptionIndex }
160
163
} ,
161
164
[ ActionTypes . GoToOption ] ( state , action ) {
162
- if ( state . dataRef . current . disabled ) return state
165
+ if ( state . dataRef . current ? .disabled ) return state
163
166
if (
164
- state . dataRef . current . optionsRef . current &&
165
- ! state . dataRef . current . optionsPropsRef . current . static &&
167
+ state . dataRef . current ? .optionsRef . current &&
168
+ ! state . dataRef . current ? .optionsPropsRef . current . static &&
166
169
state . comboboxState === ComboboxState . Closed
167
170
) {
168
171
return state
@@ -203,7 +206,7 @@ let reducers: {
203
206
204
207
// Check if we need to make the newly registered option active.
205
208
if ( state . activeOptionIndex === null ) {
206
- if ( state . dataRef . current . isSelected ( action . dataRef . current . value ) ) {
209
+ if ( state . dataRef . current ? .isSelected ( action . dataRef . current . value ) ) {
207
210
adjustedState . activeOptionIndex = adjustedState . options . indexOf ( option )
208
211
}
209
212
}
@@ -214,7 +217,7 @@ let reducers: {
214
217
activationTrigger : ActivationTrigger . Other ,
215
218
}
216
219
217
- if ( state . dataRef . current . __demoMode && state . dataRef . current . value === undefined ) {
220
+ if ( state . dataRef . current ? .__demoMode && state . dataRef . current . value === undefined ) {
218
221
nextState . activeOptionIndex = 0
219
222
}
220
223
0 commit comments