Usage

Scroll after adding content

tsx
import { Button, For, ref, Scroll, signal, Text, VStack } from 'kuito';
import type { ScrollHandle } from 'kuito';

function Chat() {
  const messages = signal<string[]>([]);
  const thread = ref<ScrollHandle>();

  function send() {
    messages.value = [...messages.value, 'Message ' + (messages.value.length + 1)];
    thread.current?.scrollToEnd();
  }

  return (
    <VStack flex={1} gap={8}>
      <Scroll ref={thread} flex={1}>
        <For each={messages}>{(message) => <Text>{message}</Text>}</For>
      </Scroll>
      <Button onPress={send}>Send</Button>
    </VStack>
  );
}

Type declaration

ts
export interface ScrollHandle extends ElementHandle {
  /**
   * Scrolls to `offset` points along the view's axis, or to `page`, a whole
   * view length each from 0, as `paging` rests; animated by default.
   */
  scrollTo(
    params: { offset: number; animated?: boolean } | { page: number; animated?: boolean },
  ): void;
  /** Scrolls to the end of the content, including what the same update added. */
  scrollToEnd(params?: { animated?: boolean }): void;
}

Members 11

NameTypeRequiredDescription
scrollTo(params: { offset: number; animated?: boolean;} | { page: number; animated?: boolean;}) => voidYesScrolls to offset points along the view's axis, or to page, a whole view length each from 0, as paging rests; animated by default.
scrollToEnd(params?: { animated?: boolean;}) => voidYesScrolls to the end of the content, including what the same update added.
idreadonlystringYes—
parentreadonlyElementHandleYes—
childrenreadonlyElementHandle[]Yes—
focus() => voidYes—
blur() => voidYes—
setProperty<K extends keyof ElementProperties>(key: K, value: ElementProperties[K] | null) => voidYesSets a native prop on the view now, until its binding writes it again.
addEventListener(type: string, fn: (e: KuitoNativeEvent) => void, options?: boolean | { capture?: boolean; once?: boolean; signal?: AbortSignal;}) => voidYes—
removeEventListener(type: string, fn: (e: KuitoNativeEvent) => void, options?: boolean | { capture?: boolean;}) => voidYes—
dispatchEvent(event: { type: string; bubbles?: boolean; cancelable?: boolean;}) => booleanYesSends an event through the tree, capture to bubble, as a native one travels: a KuitoCustomEvent, or any object with a type. False when a listener called preventDefault() on a cancelable event.
scrollTo — method signatures

Signatures

ts
(params: { offset: number; animated?: boolean; } | { page: number; animated?: boolean; }): void

Parameters

NameTypeRequiredDescription
params{ offset: number; animated?: boolean;} | { page: number; animated?: boolean;}Yes—

Returns

void

scrollToEnd — method signatures

Signatures

ts
(params?: { animated?: boolean; }): void

Parameters

NameTypeRequiredDescription
params{ animated?: boolean;}No—

Returns

void

focus — method signatures

Signatures

ts
(): void

Parameters

No parameters.

Returns

void

blur — method signatures

Signatures

ts
(): void

Parameters

No parameters.

Returns

void

setProperty — method signatures

Signatures

ts
<K extends keyof ElementProperties>(key: K, value: ElementProperties[K] | null): void

Type parameters

NameConstraintDefault
Kkeyof ElementProperties—

Parameters

NameTypeRequiredDescription
keyKYes—
valueElementProperties[K]Yes—

Returns

void

addEventListener — method signatures

Signatures

ts
(type: string, fn: (e: KuitoNativeEvent) => void, options?: boolean | { capture?: boolean; once?: boolean; signal?: AbortSignal; }): void

Parameters

NameTypeRequiredDescription
typestringYes—
fn(e: KuitoNativeEvent) => voidYes—
optionsboolean | { capture?: boolean; once?: boolean; signal?: AbortSignal;}No—

Returns

void

removeEventListener — method signatures

Signatures

ts
(type: string, fn: (e: KuitoNativeEvent) => void, options?: boolean | { capture?: boolean; }): void

Parameters

NameTypeRequiredDescription
typestringYes—
fn(e: KuitoNativeEvent) => voidYes—
optionsboolean | { capture?: boolean;}No—

Returns

void

dispatchEvent — method signatures

Signatures

ts
(event: { type: string; bubbles?: boolean; cancelable?: boolean; }): boolean

Parameters

NameTypeRequiredDescription
event{ type: string; bubbles?: boolean; cancelable?: boolean;}Yes—

Returns

boolean

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