Usage

Handle event propagation and cancellation.

tsx
// Handle event propagation and cancellation.
import { Box, Button, onMount, ref, signal, type KuitoNativeEvent } from 'kuito';

const saving = signal(false);

function Form(props: { onSave: () => void }) {
  const form = ref();

  // In the capture phase the form sees a press before the button inside it does,
  // and stops it while a save is running.
  const guard = (event: KuitoNativeEvent) => {
    if (saving.value) event.stopPropagation();
  };

  onMount(() => form.current?.addEventListener('press', guard, { capture: true }));

  return (
    <Box ref={form}>
      <Button onPress={props.onSave}>Save</Button>
    </Box>
  );
}

Type declaration

ts
export interface KuitoNativeEvent {
  type: string;
  bubbles: boolean;
  cancelable: boolean;
  readonly isTrusted?: boolean;
  target?: ElementHandle;
  currentTarget?: ElementHandle | null;
  defaultPrevented?: boolean;
  eventPhase?: number;
  stopPropagation(): void;
  stopImmediatePropagation(): void;
  preventDefault(): void;
  composedPath(): ElementHandle[];
}

Members 12

NameTypeRequiredDescription
typestringYes—
bubblesbooleanYes—
cancelablebooleanYes—
isTrustedreadonlybooleanNo—
targetElementHandleNo—
currentTargetElementHandleNo—
defaultPreventedbooleanNo—
eventPhasenumberNo—
stopPropagation() => voidYes—
stopImmediatePropagation() => voidYes—
preventDefault() => voidYes—
composedPath() => ElementHandle[]Yes—
stopPropagation — method signatures

Signatures

ts
(): void

Parameters

No parameters.

Returns

void

stopImmediatePropagation — method signatures

Signatures

ts
(): void

Parameters

No parameters.

Returns

void

preventDefault — method signatures

Signatures

ts
(): void

Parameters

No parameters.

Returns

void

composedPath — method signatures

Signatures

ts
(): ElementHandle[]

Parameters

No parameters.

Returns

ElementHandle[]

Generated from the public TypeScript declarations: signatures, props and defaults come from the checked source, descriptions from its JSDoc. No defaults are invented.