File tree Expand file tree Collapse file tree 4 files changed +22
-1
lines changed
packages/atri-app-core/src Expand file tree Collapse file tree 4 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -215,7 +215,9 @@ type SubscribeStates =
215215 | typeof OUTSIDE_CANVAS
216216 | typeof COMPONENT_CREATED
217217 | "hover"
218- | "hoverEnd" ;
218+ | "hoverEnd"
219+ | "focus"
220+ | "focusEnd" ;
219221
220222export function createCanvasMachine ( id : string ) {
221223 const subscribers : { [ key in SubscribeStates ] : Callback [ ] } = {
@@ -227,6 +229,8 @@ export function createCanvasMachine(id: string) {
227229 [ COMPONENT_CREATED ] : [ ] ,
228230 hover : [ ] ,
229231 hoverEnd : [ ] ,
232+ focus : [ ] ,
233+ focusEnd : [ ] ,
230234 } ;
231235 function subscribeCanvasMachine ( state : SubscribeStates , cb : Callback ) {
232236 subscribers [ state ] . push ( cb ) ;
Original file line number Diff line number Diff line change 11import { NormalComponentRendererProps } from "../../types" ;
22import { componentStoreApi } from "../../api" ;
33import { useAssignComponentId } from "../hooks/useAssignComponentId" ;
4+ import { useFocusComponent } from "../hooks/useFocusComponent" ;
45
56export function NormalComponentRenderer ( props : NormalComponentRendererProps ) {
67 const {
@@ -10,5 +11,6 @@ export function NormalComponentRenderer(props: NormalComponentRendererProps) {
1011 callbacks,
1112 } = componentStoreApi . getComponent ( props . id ) ! ;
1213 useAssignComponentId ( { id : props . id } ) ;
14+ useFocusComponent ( { id : props . id } ) ;
1315 return < Comp { ...compProps } ref = { ref } { ...callbacks } /> ;
1416}
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import { NormalComponentRenderer } from "../NormalComponentRenderer/NormalCompon
44import { useAssignParentMarker } from "../hooks/useAssignParentMaker" ;
55import { useAssignComponentId } from "../hooks/useAssignComponentId" ;
66import { useHandleNewChild } from "./hooks/useHandleNewChild" ;
7+ import { useFocusComponent } from "../hooks/useFocusComponent" ;
78
89export function ParentComponentRenderer ( props : ParentComponentRendererProps ) {
910 const {
@@ -15,6 +16,7 @@ export function ParentComponentRenderer(props: ParentComponentRendererProps) {
1516 const { children } = useHandleNewChild ( props ) ;
1617 useAssignParentMarker ( { id : props . id } ) ;
1718 useAssignComponentId ( { id : props . id } ) ;
19+ useFocusComponent ( { id : props . id } ) ;
1820 return (
1921 < Comp { ...compProps } ref = { ref } { ...callbacks } >
2022 { children . map ( ( childId ) => {
Original file line number Diff line number Diff line change 1+ import { DecoratorData } from "../../types" ;
2+ import { componentStoreApi } from "../../api/componentStoreApi" ;
3+ import { useEffect } from "react" ;
4+
5+ export function useFocusComponent ( props : DecoratorData ) {
6+ useEffect ( ( ) => {
7+ const ref = componentStoreApi . getComponentRef ( props . id ) ;
8+ if ( ref . current ) {
9+ ref . current . tabIndex = 0 ;
10+ ref . current . focus ( ) ;
11+ }
12+ } , [ props . id ] ) ;
13+ }
You can’t perform that action at this time.
0 commit comments