@@ -4,7 +4,6 @@ import React, { useCallback, useMemo, useRef } from 'react';
44
55import AccessibleInputText from '../Utils/AccessibleInputText' ;
66import navigableEvent from '../Utils/TypeFocusSink/navigableEvent' ;
7- import { ie11 } from '../Utils/detectBrowser' ;
87import { useRegisterFocusSendBox , type SendBoxFocusOptions } from '../hooks/sendBoxFocus' ;
98import { useStyleToEmotionObject } from '../hooks/internal/styleToEmotionObject' ;
109import useScrollDown from '../hooks/useScrollDown' ;
@@ -17,7 +16,9 @@ import AutoResizeTextArea from './AutoResizeTextArea';
1716import type { MutableRefObject } from 'react' ;
1817import testIds from '../testIds' ;
1918
20- const { useLocalizer, usePonyfill, useSendBoxValue, useStopDictate, useStyleOptions, useUIState } = hooks ;
19+ const { useLocalizer, useSendBoxValue, useStopDictate, useStyleOptions, useUIState } = hooks ;
20+
21+ const DEFAULT_INPUT_MODE = 'text' ;
2122
2223const ROOT_STYLE = {
2324 '&.webchat__send-box-text-box' : {
@@ -83,7 +84,6 @@ const TextBox = ({ className = '' }: Readonly<{ className?: string | undefined }
8384 const [ value , setValue ] = useSendBoxValue ( ) ;
8485 const [ { sendBoxTextBox : sendBoxTextBoxStyleSet } ] = useStyleSet ( ) ;
8586 const [ { emojiSet, sendBoxTextWrap } ] = useStyleOptions ( ) ;
86- const [ { setTimeout } ] = usePonyfill ( ) ;
8787 const [ uiState ] = useUIState ( ) ;
8888 const inputElementRef : MutableRefObject < HTMLInputElement & HTMLTextAreaElement > = useRef ( ) ;
8989 const localize = useLocalizer ( ) ;
@@ -165,44 +165,25 @@ const TextBox = ({ className = '' }: Readonly<{ className?: string | undefined }
165165 ) ;
166166
167167 const focusCallback = useCallback (
168- ( options : SendBoxFocusOptions ) => {
169- const { noKeyboard } = options ;
168+ ( { noKeyboard } : SendBoxFocusOptions ) => {
170169 const { current } = inputElementRef ;
171170
172- if ( current ) {
173- // The "disable soft keyboard on mobile devices" logic will not work on IE11. It will cause the <input> to become read-only until next focus.
174- // Thus, no mobile devices carry IE11 so we don't need to explicitly disable soft keyboard on IE11.
175- // See #3757 for repro and details.
176- if ( noKeyboard && ! ie11 ) {
177- // To not activate the virtual keyboard while changing focus to an input, we will temporarily set it as read-only and flip it back.
178- // https://stackoverflow.com/questions/7610758/prevent-iphone-default-keyboard-when-focusing-an-input/7610923
179- const readOnly = current . getAttribute ( 'readonly' ) ;
180-
181- current . setAttribute ( 'readonly' , 'readonly' ) ;
182-
183- options . waitUntil (
184- ( async function ( ) {
185- // TODO: [P2] We should update this logic to handle quickly-successive `focusCallback`.
186- // If a succeeding `focusCallback` is being called, the `setTimeout` should run immediately.
187- // Or the second `focusCallback` should not set `readonly` to `true`.
188- await new Promise ( resolve => setTimeout ( resolve , 0 ) ) ;
189-
190- if ( current ) {
191- current . focus ( ) ;
192- readOnly ? current . setAttribute ( 'readonly' , readOnly ) : current . removeAttribute ( 'readonly' ) ;
193- }
194- } ) ( )
195- ) ;
196- } else {
197- current . focus ( ) ;
198- }
199- }
171+ // Setting `inputMode` to `none` temporarily to suppress soft keyboard in iOS.
172+ // We will revert the change once the end-user tap on the send box.
173+ // This code path is only triggered when the user press "send" button to send the message, instead of pressing ENTER key.
174+ noKeyboard && current ?. setAttribute ( 'inputmode' , 'none' ) ;
175+ current ?. focus ( ) ;
200176 } ,
201- [ inputElementRef , setTimeout ]
177+ [ inputElementRef ]
202178 ) ;
203179
204180 useRegisterFocusSendBox ( focusCallback ) ;
205181
182+ const handleClick = useCallback (
183+ ( { currentTarget } ) => currentTarget . setAttribute ( 'inputmode' , DEFAULT_INPUT_MODE ) ,
184+ [ ]
185+ ) ;
186+
206187 const emojiMap = useMemo ( ( ) => new Map < string , string > ( Object . entries ( emojiSet ) ) , [ emojiSet ] ) ;
207188
208189 return (
@@ -225,8 +206,9 @@ const TextBox = ({ className = '' }: Readonly<{ className?: string | undefined }
225206 disabled = { disabled }
226207 emojiMap = { emojiMap }
227208 enterKeyHint = "send"
228- inputMode = "text"
209+ inputMode = { DEFAULT_INPUT_MODE }
229210 onChange = { setValue }
211+ onClick = { handleClick }
230212 onKeyDownCapture = { disabled ? undefined : handleKeyDownCapture }
231213 onKeyPress = { disabled ? undefined : handleKeyPress }
232214 placeholder = { typeYourMessageString }
@@ -244,8 +226,9 @@ const TextBox = ({ className = '' }: Readonly<{ className?: string | undefined }
244226 disabled = { disabled }
245227 emojiMap = { emojiMap }
246228 enterKeyHint = "send"
247- inputMode = "text"
229+ inputMode = { DEFAULT_INPUT_MODE }
248230 onChange = { setValue }
231+ onClick = { handleClick }
249232 onKeyDownCapture = { disabled ? undefined : handleKeyDownCapture }
250233 onKeyPress = { disabled ? undefined : handleKeyPress }
251234 placeholder = { typeYourMessageString }
0 commit comments