1- import { Accessor , Component , createMemo , For , JSX , onCleanup , onMount , Show } from 'solid-js'
1+ import { Accessor , Component , createEffect , createMemo , For , JSX , onCleanup , onMount , Show } from 'solid-js'
22import { Dynamic } from 'solid-js/web'
33import { BlockItem , Item , ItemId } from './Item'
44import {
@@ -262,7 +262,6 @@ export function BlockTree<K, T>(props: BlockTreeProps<K, T>) {
262262 const select = ( ) => {
263263 const { mode, keys } = nextSelection
264264 props . onSelectionChange ?.( { kind : 'blocks' , key : item . key , mode, blocks : keys } )
265- focusElement . focus ( { preventScroll : true } )
266265 }
267266
268267 if ( nextSelection . onClick ) {
@@ -287,6 +286,18 @@ export function BlockTree<K, T>(props: BlockTreeProps<K, T>) {
287286 }
288287 }
289288
289+ createEffect ( ( ) => {
290+ const selection = props . selection
291+ if ( ! selection ) return
292+
293+ const hasSelection = ( selection . blocks ?. length ?? 0 ) > 0 || selection . place != null
294+ const hasFocus = document . activeElement === focusElement
295+
296+ if ( hasSelection && ! hasFocus ) {
297+ focusElement . focus ( { preventScroll : true } )
298+ }
299+ } )
300+
290301 const renderItem = (
291302 item : Item < K , T > ,
292303 tree : Accessor < VirtualTree < K , T > > ,
0 commit comments