/ ink / events / focus-event.ts
focus-event.ts
 1  import { type EventTarget, TerminalEvent } from './terminal-event.js'
 2  
 3  /**
 4   * Focus event for component focus changes.
 5   *
 6   * Dispatched when focus moves between elements. 'focus' fires on the
 7   * newly focused element, 'blur' fires on the previously focused one.
 8   * Both bubble, matching react-dom's use of focusin/focusout semantics
 9   * so parent components can observe descendant focus changes.
10   */
11  export class FocusEvent extends TerminalEvent {
12    readonly relatedTarget: EventTarget | null
13  
14    constructor(
15      type: 'focus' | 'blur',
16      relatedTarget: EventTarget | null = null,
17    ) {
18      super(type, { bubbles: true, cancelable: false })
19      this.relatedTarget = relatedTarget
20    }
21  }