Scenario

Mac accent menu composition events are inconsistent

On macOS, using the accent menu (e.g., holding vowel key to select accented character, or using option+key combinations) does NOT consistently trigger standard IME composition events (`compositionstart`, `compositionupdate`, `compositionend`). This makes it difficult to distinguish accent menu input from IME input or regular keyboard input.

ime
Scenario ID
scenario-mac-accent-menu-composition

Details

On macOS, when using the built-in accent menu to insert accented characters or special symbols, the standard IME composition events do not fire consistently. This affects Japanese, Chinese, and other language IME detection.

Problem Description

This issue occurs specifically when:

  1. User is on macOS
  2. User uses accent menu (hold vowel + accent menu, or option+key combinations)
  3. Or user switches IME languages during typing

Expected Behavior

  • Standard composition events should fire: compositionstartcompositionupdatecompositionend
  • Should be distinguishable from regular keyboard input
  • Consistent behavior regardless of accent menu or full IME

Actual Behavior (macOS Bug)

  • Inconsistent events: Sometimes compositionstart fires, sometimes it doesn’t
  • Missing compositionupdate: When compositionstart fires, compositionupdate may not fire at all
  • Missing compositionend: Sometimes compositionend doesn’t fire, or fires at unexpected times
  • Hard to distinguish: Difficult to tell if user is using accent menu or full IME without workarounds

Affected Browsers

  • Safari (macOS) - Issue confirmed
  • Chrome (macOS) - Issue confirmed
  • Firefox (macOS) - May have similar issues

Root Cause

macOS treats accent menu input differently from full IME composition:

  1. Accent menu is handled at system level (NSResponder)
  2. Event propagation to browser layer is inconsistent
  3. IME event spec assumes full IME composition, not partial accent selection

Workarounds

  1. Check inputType instead of relying on composition events:

    editor.addEventListener('beforeinput', (e) => {
      // Use inputType to detect what's happening
      if (e.inputType === 'insertCompositionText') {
        // Definitely IME composition
      } else if (e.inputType === 'insertText') {
        // Could be accent menu or regular typing
        // Check length and other indicators
      }
    });
  2. Track keydown/keyup state as fallback:

    let keydownCount = 0;
    let keyupCount = 0;
    
    editor.addEventListener('keydown', () => {
      keydownCount++;
    });
    
    editor.addEventListener('keyup', () => {
      keyupCount++;
      // If we have keydown+keyup without composition events, likely accent menu
    });
  3. Use setTimeout to check for delayed compositionend:

    let compositionTimer = null;
    
    editor.addEventListener('compositionstart', () => {
      clearTimeout(compositionTimer);
    });
    
    editor.addEventListener('compositionend', () => {
      compositionTimer = setTimeout(() => {
        // Compose ended, do cleanup
      }, 100);
    });
  4. Detect macOS specifically:

    const isMac = navigator.platform.startsWith('Mac');
    const isAccelMenu = (e) => {
      // Check for option key, or vowel key hold
      return e.altKey || isVowelKey(e.key);
    };

References

Scenario flow

Visual view of how this scenario connects to its concrete cases and environments. Nodes can be dragged and clicked.

React Flow mini map

Variants

Each row is a concrete case for this scenario, with a dedicated document and playground.

Case OS Device Browser Keyboard Status
ce-0251-mac-accent-menu-composition-en macOS 13+ Desktop (Mac) Any Safari 17+ English (QWERTY) draft

Cases

Open a case to see the detailed description and its dedicated playground.

Related Scenarios

Other scenarios that share similar tags or category.

Tags: composition, ime

beforeinput and input events have different inputType values

During IME composition or in certain browser/IME combinations, the beforeinput event may have a different inputType than the corresponding input event. For example, beforeinput may fire with insertCompositionText while input fires with deleteContentBackward. This mismatch can cause handlers to misinterpret the actual DOM change and requires storing beforeinput's targetRanges for use in input event handling.

1 case
Tags: composition, ime

Selection mismatch between beforeinput and input events

The selection (window.getSelection()) in beforeinput events can differ from the selection in corresponding input events. This mismatch can occur during IME composition, text prediction, or when typing adjacent to formatted elements like links. The selection in beforeinput may include adjacent formatted text, while input selection reflects the final cursor position.

1 case
Tags: composition, ime

getTargetRanges() returns empty array in beforeinput events

The getTargetRanges() method in beforeinput events may return an empty array or undefined in various scenarios, including text prediction, certain IME compositions, or specific browser/device combinations. When getTargetRanges() is unavailable, developers must rely on window.getSelection() as a fallback, but this may be less accurate.

1 case

Comments & Discussion

Have questions, suggestions, or want to share your experience? Join the discussion below.