Utilização

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>
  );
}

Declaração do tipo

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[];
}

Membros 12

NomeTipoObrigatórioDescrição
typestringSim—
bubblesbooleanSim—
cancelablebooleanSim—
isTrustedsó de leiturabooleanNão—
targetElementHandleNão—
currentTargetElementHandleNão—
defaultPreventedbooleanNão—
eventPhasenumberNão—
stopPropagation() => voidSim—
stopImmediatePropagation() => voidSim—
preventDefault() => voidSim—
composedPath() => ElementHandle[]Sim—
stopPropagation — assinaturas de método

Assinaturas

ts
(): void

Parâmetros

Sem parâmetros.

Devolve

void

stopImmediatePropagation — assinaturas de método

Assinaturas

ts
(): void

Parâmetros

Sem parâmetros.

Devolve

void

preventDefault — assinaturas de método

Assinaturas

ts
(): void

Parâmetros

Sem parâmetros.

Devolve

void

composedPath — assinaturas de método

Assinaturas

ts
(): ElementHandle[]

Parâmetros

Sem parâmetros.

Devolve

ElementHandle[]

Gerado a partir das declarações TypeScript públicas: assinaturas, props e predefinições vêm da fonte verificada, as descrições da sua JSDoc. Nenhuma predefinição é inventada.