@@ -35,7 +35,7 @@ export const useUiKitState: <TElement extends UiKit.ActionableElement>(
35
35
| { target : { value : UiKit . ActionOf < TElement > } }
36
36
) => void
37
37
] = ( rest , context ) => {
38
- const { blockId, actionId, appId } = rest ;
38
+ const { blockId, actionId, appId, dispatchActionConfig } = rest ;
39
39
const {
40
40
action,
41
41
appId : appIdFromContext ,
@@ -72,6 +72,27 @@ export const useUiKitState: <TElement extends UiKit.ActionableElement>(
72
72
setLoading ( false ) ;
73
73
} ) ;
74
74
75
+ // Used for triggering actions on text inputs. Removing the load state
76
+ // makes the text input field remain focused after running the action
77
+ const noLoadStateActionFunction = useMutableCallback ( async ( e ) => {
78
+ const {
79
+ target : { value } ,
80
+ } = e ;
81
+ setValue ( value ) ;
82
+ state && ( await state ( { blockId, appId, actionId, value, viewId } , e ) ) ;
83
+ await action (
84
+ {
85
+ blockId,
86
+ appId : appId || appIdFromContext ,
87
+ actionId,
88
+ value,
89
+ viewId,
90
+ dispatchActionConfig,
91
+ } ,
92
+ e
93
+ ) ;
94
+ } ) ;
95
+
75
96
const stateFunction = useMutableCallback ( async ( e ) => {
76
97
const {
77
98
target : { value } ,
@@ -94,6 +115,23 @@ export const useUiKitState: <TElement extends UiKit.ActionableElement>(
94
115
[ loading , setLoading , error , value ]
95
116
) ;
96
117
118
+ if ( context === UiKit . BlockContext . FORM ) {
119
+ if (
120
+ rest . type === 'plain_text_input' &&
121
+ Array . isArray ( rest ?. dispatchActionConfig ) &&
122
+ rest . dispatchActionConfig . includes ( 'on_character_entered' )
123
+ ) {
124
+ return [ result , noLoadStateActionFunction ] ;
125
+ }
126
+
127
+ if (
128
+ Array . isArray ( rest ?. dispatchActionConfig ) &&
129
+ rest . dispatchActionConfig . includes ( 'on_item_selected' )
130
+ ) {
131
+ return [ result , actionFunction ] ;
132
+ }
133
+ }
134
+
97
135
if (
98
136
context &&
99
137
[ UiKit . BlockContext . SECTION , UiKit . BlockContext . ACTION ] . includes ( context )
0 commit comments