Skip to content

Commit

Permalink
refactor: implement focus change
Browse files Browse the repository at this point in the history
  • Loading branch information
segunadebayo committed Aug 16, 2023
1 parent e541829 commit c5ae307
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions packages/machines/accordion/src/accordion.machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ export function machine(userContext: UserDefinedContext) {
triggerEl?.focus()
},
setFocusedValue(ctx, evt) {
ctx.focusedValue = evt.value
set.focusedValue(ctx, evt.value)
},
clearFocusedValue(ctx) {
ctx.focusedValue = null
set.focusedValue(ctx, null)
},
setValue(ctx, evt) {
set.value(ctx, evt.value)
Expand All @@ -134,7 +134,7 @@ const invoke = {
ctx.onChange?.({ value: ctx.value })
},
focusChange(ctx: MachineContext) {
ctx.onFocusChange?.({ focusedValue: ctx.focusedValue })
ctx.onFocusChange?.({ value: ctx.focusedValue })
},
}

Expand All @@ -145,5 +145,6 @@ const set = {
},
focusedValue(ctx: MachineContext, value: string | null) {
ctx.focusedValue = value
invoke.focusChange(ctx)
},
}
2 changes: 1 addition & 1 deletion packages/machines/accordion/src/accordion.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type ChangeDetails = {
}

export type FocusChangeDetails = {
focusedValue: string | null
value: string | null
}

type PublicContext = DirectionProperty &
Expand Down

0 comments on commit c5ae307

Please sign in to comment.