Skip to content

Commit ccf5fa4

Browse files
committed
Guard completion acceptance against Safari IME confirmation
1 parent 02d906e commit ccf5fa4

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

‎src/App.test.tsx‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,13 @@ describe("Stack Playground", () => {
295295
expect(screen.queryByRole("listbox")).not.toBeInTheDocument()
296296
fireEvent.compositionEnd(editor)
297297
await screen.findByRole("listbox")
298+
fireEvent.keyDown(editor, { key: "Enter", isComposing: true })
299+
expect(editor).toHaveValue(source)
300+
expect(screen.getByRole("listbox")).toBeInTheDocument()
301+
// Safari's confirming Enter may arrive after compositionend with isComposing false.
302+
fireEvent.keyDown(editor, { key: "Enter", keyCode: 229, isComposing: false })
303+
expect(editor).toHaveValue(source)
304+
expect(screen.getByRole("listbox")).toBeInTheDocument()
298305
await user.keyboard("{ArrowDown}{Enter}")
299306

300307
expect(editor).toHaveValue(source.slice(0, editStart) + "group")

‎src/components/editor-pane.tsx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,9 @@ export function EditorPane({
408408
source={source}
409409
/>
410410

411+
<label className="sr-only" htmlFor="stack-source">
412+
Stack source
413+
</label>
411414
<textarea
412415
aria-activedescendant={activeOptionId}
413416
aria-autocomplete="list"
@@ -457,6 +460,8 @@ export function EditorPane({
457460
}}
458461
onKeyDown={(event) => {
459462
if (composingRef.current || event.nativeEvent.isComposing) return
463+
// Safari can deliver compositionend before the IME-confirming Enter.
464+
if (event.key === "Enter" && event.nativeEvent.keyCode === 229) return
460465
if (event.key === "Enter" && (event.metaKey || event.ctrlKey)) {
461466
event.preventDefault()
462467
setCompletion(null)

0 commit comments

Comments
 (0)