@@ -35,7 +35,9 @@ export function NotificationPicker({
35
35
const [ enableNotification , setEnableNotification ] = useState < boolean > (
36
36
model . notification ?. enableNotification ?? true
37
37
) ;
38
- const sendToString = model . notification ?. sendTo ?. join ( ', ' ) || '' ;
38
+ const [ sendToInput , setSendToInput ] = useState < string > (
39
+ model . notification ?. sendTo ?. join ( ', ' ) || ''
40
+ ) ;
39
41
40
42
const enableNotificationChange = ( e : React . ChangeEvent < HTMLInputElement > ) => {
41
43
const updatedEnableNotification = e . target . checked ;
@@ -67,17 +69,27 @@ export function NotificationPicker({
67
69
[ selectedEvents , model , modelChange ]
68
70
) ;
69
71
70
- const sendToChange = useCallback (
71
- ( e : React . ChangeEvent < HTMLInputElement > ) => {
72
- const { value } = e . target ;
73
- const sendToArray = value . split ( ',' ) . map ( sendToStr => sendToStr . trim ( ) ) ;
74
- const updatedNotification = {
75
- ...model . notification ,
76
- sendTo : sendToArray
77
- } ;
78
- modelChange ( { ...model , notification : updatedNotification } ) ;
72
+ const sendToChange = useCallback ( ( e : React . ChangeEvent < HTMLInputElement > ) => {
73
+ setSendToInput ( e . target . value ) ;
74
+ } , [ ] ) ;
75
+
76
+ const handleBlur = useCallback ( ( ) => {
77
+ const emailArray = sendToInput
78
+ . split ( ',' )
79
+ . map ( email => email . trim ( ) )
80
+ . filter ( email => email ) ;
81
+ const updatedNotification = { ...model . notification , sendTo : emailArray } ;
82
+ modelChange ( { ...model , notification : updatedNotification } ) ;
83
+ } , [ sendToInput , model , modelChange ] ) ;
84
+
85
+ const handleKeyDown = useCallback (
86
+ ( e : React . KeyboardEvent ) => {
87
+ if ( e . key === 'Enter' ) {
88
+ e . preventDefault ( ) ;
89
+ handleBlur ( ) ;
90
+ }
79
91
} ,
80
- [ model , modelChange ]
92
+ [ handleBlur ]
81
93
) ;
82
94
83
95
const deleteSelectedEvent = useCallback (
@@ -113,10 +125,12 @@ export function NotificationPicker({
113
125
114
126
< TextField
115
127
label = { trans . __ ( 'Send To' ) }
116
- value = { sendToString }
128
+ value = { sendToInput }
117
129
name = "sendTo"
118
130
variant = "outlined"
119
131
onChange = { sendToChange }
132
+ onBlur = { handleBlur }
133
+ onKeyDown = { handleKeyDown }
120
134
disabled = { ! enableNotification }
121
135
/>
122
136
< NotificationEventsSelect
0 commit comments