@@ -53,6 +53,7 @@ interface StateDefinition {
53
53
comboboxPropsRef : MutableRefObject < {
54
54
value : unknown
55
55
onChange ( value : unknown ) : void
56
+ __demoMode : boolean
56
57
} >
57
58
inputPropsRef : MutableRefObject < {
58
59
displayValue ?( item : unknown ) : string
@@ -146,7 +147,7 @@ let reducers: {
146
147
( a , z ) => orderMap [ a . id ] - orderMap [ z . id ]
147
148
)
148
149
149
- return {
150
+ let nextState = {
150
151
...state ,
151
152
options,
152
153
activeOptionIndex : ( ( ) => {
@@ -158,6 +159,15 @@ let reducers: {
158
159
return options . indexOf ( currentActiveOption )
159
160
} ) ( ) ,
160
161
}
162
+
163
+ if (
164
+ state . comboboxPropsRef . current . __demoMode &&
165
+ state . comboboxPropsRef . current . value === undefined
166
+ ) {
167
+ nextState . activeOptionIndex = 0
168
+ }
169
+
170
+ return nextState
161
171
} ,
162
172
[ ActionTypes . UnregisterOption ] : ( state , action ) => {
163
173
let nextOptions = state . options . slice ( )
@@ -243,6 +253,7 @@ let ComboboxRoot = forwardRefWithAs(function Combobox<
243
253
let comboboxPropsRef = useRef < StateDefinition [ 'comboboxPropsRef' ] [ 'current' ] > ( {
244
254
value,
245
255
onChange,
256
+ __demoMode,
246
257
} )
247
258
let optionsPropsRef = useRef < StateDefinition [ 'optionsPropsRef' ] [ 'current' ] > ( {
248
259
static : false ,
@@ -853,9 +864,20 @@ function Option<
853
864
dispatch ( { type : ActionTypes . GoToOption , focus : Focus . Specific , id } )
854
865
} , [ state . comboboxState , selected , id ] )
855
866
867
+ let enableScrollIntoView = useRef ( state . comboboxPropsRef . current . __demoMode ? false : true )
868
+ useIsoMorphicEffect ( ( ) => {
869
+ if ( ! state . comboboxPropsRef . current . __demoMode ) return
870
+ let d = disposables ( )
871
+ d . requestAnimationFrame ( ( ) => {
872
+ enableScrollIntoView . current = true
873
+ } )
874
+ return d . dispose
875
+ } , [ ] )
876
+
856
877
useIsoMorphicEffect ( ( ) => {
857
878
if ( state . comboboxState !== ComboboxStates . Open ) return
858
879
if ( ! active ) return
880
+ if ( ! enableScrollIntoView . current ) return
859
881
let d = disposables ( )
860
882
d . requestAnimationFrame ( ( ) => {
861
883
document . getElementById ( id ) ?. scrollIntoView ?.( { block : 'nearest' } )
0 commit comments