File tree Expand file tree Collapse file tree 4 files changed +19
-4
lines changed Expand file tree Collapse file tree 4 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -34,3 +34,4 @@ yarn-error.log*
34
34
! .yarn /versions
35
35
36
36
.parcel-cache
37
+ .vscode
Original file line number Diff line number Diff line change
1
+ describe ( "Testing the Cities Demo" , ( ) => {
2
+ beforeEach ( ( ) => {
3
+ cy . visit ( "http://localhost:3000/cities" ) ;
4
+ } ) ;
5
+
6
+ it ( "Does not steel the selection when the selection prop changes" , ( ) => {
7
+ cy . get ( "button" ) . contains ( "Select San Francisco" ) . click ( ) ;
8
+ cy . focused ( ) . invoke ( "is" , "button" ) . should ( "equal" , true ) ;
9
+ cy . focused ( ) . should ( "have.text" , "Select San Francisco" ) ;
10
+ } ) ;
11
+ } ) ;
Original file line number Diff line number Diff line change @@ -65,7 +65,7 @@ export function TreeProvider<T>({
65
65
/* Change selection based on props */
66
66
useEffect ( ( ) => {
67
67
if ( api . props . selection ) {
68
- api . select ( api . props . selection ) ;
68
+ api . select ( api . props . selection , { focus : false } ) ;
69
69
} else {
70
70
api . deselectAll ( ) ;
71
71
}
Original file line number Diff line number Diff line change @@ -323,15 +323,18 @@ export class TreeApi<T> {
323
323
this . focus ( this . at ( index ) ) ;
324
324
}
325
325
326
- select ( node : Identity , opts : { align ?: Align } = { } ) {
326
+ select ( node : Identity , opts : { align ?: Align ; focus ?: boolean } = { } ) {
327
327
if ( ! node ) return ;
328
+ const changeFocus = opts . focus !== false ;
328
329
const id = identify ( node ) ;
329
- this . dispatch ( focus ( id ) ) ;
330
+ if ( changeFocus ) this . dispatch ( focus ( id ) ) ;
330
331
this . dispatch ( selection . only ( id ) ) ;
331
332
this . dispatch ( selection . anchor ( id ) ) ;
332
333
this . dispatch ( selection . mostRecent ( id ) ) ;
333
334
this . scrollTo ( id , opts . align ) ;
334
- if ( this . focusedNode ) safeRun ( this . props . onFocus , this . focusedNode ) ;
335
+ if ( this . focusedNode && changeFocus ) {
336
+ safeRun ( this . props . onFocus , this . focusedNode ) ;
337
+ }
335
338
safeRun ( this . props . onSelect , this . selectedNodes ) ;
336
339
}
337
340
You can’t perform that action at this time.
0 commit comments