Skip to content

Commit d0be59d

Browse files
committed
Fix tests
1 parent 78aabb5 commit d0be59d

File tree

3 files changed

+30
-16
lines changed

3 files changed

+30
-16
lines changed

__tests__/html2/hooks/useFocus.sendBox.pure.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@
3939

4040
await renderHook();
4141

42-
expect(document.activeElement).not.toEqual(pageElements.sendBoxTextBox());
42+
expect(document.activeElement === pageElements.sendBoxTextBox()).toBe(false);
4343

4444
const focus = await renderHook(() => useFocus());
4545

46-
focus('sendBox');
46+
await focus('sendBox');
4747

48-
expect(document.activeElement).toEqual(pageElements.sendBoxTextBox());
48+
expect(document.activeElement === pageElements.sendBoxTextBox()).toBe(true);
4949
});
5050
</script>
5151
</body>

__tests__/html2/transcript/navigation/useObserveTranscriptFocus.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html lang="en-US">
33
<head>
44
<link href="/assets/index.css" rel="stylesheet" type="text/css" />
@@ -75,7 +75,7 @@
7575
// THEN: It should send a "transcriptfocus" event with the third-last activity, which is a card activity (#29).
7676
expect(transcriptFocusActivityIDHistory).toEqual(['31', '30', '29']);
7777

78-
// WHEN: Pressing ENTER key while focusingo on the card activity (#29).
78+
// WHEN: Pressing ENTER key while focusing on the card activity (#29).
7979
await host.sendKeys('ENTER');
8080

8181
// THEN: It should not send another event because the transcript did not gain any new focus.

packages/component/src/SendBox/TextBox.tsx

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -177,17 +177,31 @@ const TextBox = ({ className = '' }: Readonly<{ className?: string | undefined }
177177
(async () => {
178178
const { current } = inputElementRef;
179179

180-
// Setting `inputMode` to `none` temporarily to suppress soft keyboard in iOS.
181-
// We will revert the change once the end-user tap on the send box.
182-
// This code path is only triggered when the user press "send" button to send the message, instead of pressing ENTER key.
183-
noKeyboard ? current?.setAttribute('inputmode', 'none') : current?.removeAttribute('inputmode');
184-
185-
// iOS 26.3 quirks: `HTMLElement.focus()` does not pickup `inputmode="none"` changes immediately.
186-
// We need to wait for next frame before calling `focus()`.
187-
// This is a regression from iOS 26.2.
188-
await new Promise<void>(resolve => requestIdleCallbackWithPonyfill(resolve));
189-
190-
current?.focus();
180+
if (current) {
181+
// Setting `inputMode` to `none` temporarily to suppress soft keyboard in iOS.
182+
// We will revert the change once the end-user tap on the send box.
183+
// This code path is only triggered when the user press "send" button to send the message, instead of pressing ENTER key.
184+
if (noKeyboard) {
185+
if (current.getAttribute('inputmode') !== 'none') {
186+
// Collapse the virtual keybaord if it was expanded.
187+
current.setAttribute('inputmode', 'none');
188+
189+
// iOS 26.3 quirks: `HTMLElement.focus()` does not pickup `inputmode="none"` changes immediately.
190+
// We need to wait for next frame before calling `focus()`.
191+
// This is a regression from iOS 26.2.
192+
await new Promise<void>(resolve => requestIdleCallbackWithPonyfill(resolve));
193+
}
194+
} else if (current.hasAttribute('inputmode')) {
195+
// Expanding the virtual keyboard if it was collapsed.
196+
// However, we are not pausing here to workaround iOS 26.3 quirks.
197+
// If we pause here, it will not able to handle this scenario: focus on an activity on the transcript, press A, the letter A should be inputted into the send box.
198+
// In other words, if we pause here, the event will be send to the activity/transcript, instead of the newly focused send box.
199+
// This is related to BasicTranscript.handleTranscriptKeyDownCapture().
200+
current.removeAttribute('inputmode');
201+
}
202+
203+
current?.focus();
204+
}
191205
})()
192206
);
193207
},

0 commit comments

Comments
 (0)