# API of `@koobiq/components/scrollbar`

Documented on [Scrollbar](https://koobiq.io/en/components/scrollbar.md).

## Components

### KbqScrollbar (component)

Custom scrollbar wrapper: projects content and overlays a scrollbar track over it (created by its `KbqScrollbarViewport` host directive).

```ts
@Component({ selector: 'kbq-scrollbar', exportAs: 'kbqScrollbar' })
class KbqScrollbar {
    readonly mode = input<KbqScrollbarMode>(this.options.mode, {
        alias: 'kbqScrollbarMode'
    });
    readonly hideDelay = input<number>(this.options.hideDelay, {
        alias: 'kbqScrollbarHideDelay'
    });
    readonly scrollChanges: Observable<Event>;
    getNativeElement(): HTMLElement;
    scrollTo(options: KbqScrollbarScrollToOptions): void;
    scrollToTop(behavior?: ScrollBehavior): void;
    scrollToBottom(behavior?: ScrollBehavior): void;
    scrollStart(behavior?: ScrollBehavior): void;
    scrollEnd(behavior?: ScrollBehavior): void;
    scrollToElement(
        target: HTMLElement | string,
        options?: KbqScrollbarScrollToElementOptions
    ): void;
    scrollIntoView(
        target: HTMLElement,
        behavior?: ScrollBehavior
    ): void;
    flashScrollIndicators(): void;
}
```

- `[kbqScrollbarMode]`: `KbqScrollbarMode` — Visibility mode for the scrollbar. Defaults to the app-wide `KBQ_SCROLLBAR_OPTIONS`.
- `[kbqScrollbarHideDelay]`: `number` — How long the scroll-revealed `hover`-mode track stays visible after scrolling stops, in milliseconds.
  Defaults to the app-wide `KBQ_SCROLLBAR_OPTIONS`.
- `scrollChanges`: `Observable<Event>` — Emits on every native `scroll` event of the viewport. Emits outside Angular's zone — see `CdkScrollable.elementScrolled`.
- `getNativeElement()`: `HTMLElement` — The scrollbar's native scrollable element.
- `scrollTo()`: `void` — Scrolls to the specified offsets. RTL-normalized — see `CdkScrollable.scrollTo`.
- `scrollToTop()`: `void` — Scrolls to the start of the vertical axis.
- `scrollToBottom()`: `void` — Scrolls to the end of the vertical axis.
- `scrollStart()`: `void` — Scrolls to the logical start of the horizontal axis — the right edge in RTL, left in LTR.
- `scrollEnd()`: `void` — Scrolls to the logical end of the horizontal axis — the left edge in RTL, right in LTR.
- `scrollToElement()`: `void` — Scrolls `target` (an element, or a selector resolved against this scrollbar) into view.
- `scrollIntoView()`: `void` — Scrolls `target` to the center of the viewport.
- `flashScrollIndicators()`: `void` — Briefly reveals the scrollbar track — see `KbqScrollbarViewport.flashScrollIndicators`.

## Directives

### KbqNativeScrollbar (directive)

Customizes the browser-rendered scrollbar of its host without replacing native scrolling.

```ts
@Directive({ selector: '[kbqNativeScrollbar]', exportAs: 'kbqNativeScrollbar' })
class KbqNativeScrollbar {
    readonly descendants = input<boolean>(this.options.descendants, {
        alias: 'kbqNativeScrollbarDescendants'
    });
}
```

- `[kbqNativeScrollbarDescendants]`: `boolean` — Whether browser-rendered scrollbars of descendant elements should also be customized.
  Defaults to `KBQ_NATIVE_SCROLLBAR_OPTIONS`.

### KbqScrollbarViewport (directive)

Marks its host element as the custom scrollbar's scroll target, hiding its native scrollbar whenever a custom scrollbar track replaces it.

```ts
@Directive({ selector: '[kbqScrollbarViewport]' })
class KbqScrollbarViewport {
    readonly mode = input<KbqScrollbarMode>(this.options.mode, {
        alias: 'kbqScrollbarMode'
    });
    readonly hideDelay = input<number>(this.options.hideDelay, {
        alias: 'kbqScrollbarHideDelay'
    });
    readonly flashes: Observable<void>;
    readonly scrollChanges: Observable<Event>;
    flashScrollIndicators(): void;
    scrollTo(options: KbqScrollbarScrollToOptions): void;
    scrollToTop(behavior?: ScrollBehavior): void;
    scrollToBottom(behavior?: ScrollBehavior): void;
    scrollStart(behavior?: ScrollBehavior): void;
    scrollEnd(behavior?: ScrollBehavior): void;
    scrollToElement(
        target: HTMLElement | string,
        options?: KbqScrollbarScrollToElementOptions
    ): void;
    scrollIntoView(
        target: HTMLElement,
        behavior?: ScrollBehavior
    ): void;
    getNativeElement(): HTMLElement;
}
```

- `[kbqScrollbarMode]`: `KbqScrollbarMode` — Visibility mode for this viewport's scrollbar. Defaults to the app-wide `KBQ_SCROLLBAR_OPTIONS`.
- `[kbqScrollbarHideDelay]`: `number` — How long the scroll-revealed `hover`-mode track stays visible after scrolling stops, in milliseconds.
  Defaults to the app-wide `KBQ_SCROLLBAR_OPTIONS`.
- `flashes`: `Observable<void>` — Emits when `flashScrollIndicators` is called.
- `scrollChanges`: `Observable<Event>` — Emits on every native `scroll` event of the viewport. Emits outside Angular's zone — see `CdkScrollable.elementScrolled`.
- `flashScrollIndicators()`: `void` — Briefly reveals an overflowing `hover`-mode scrollbar.
- `scrollTo()`: `void` — Scrolls to the specified offsets. RTL-normalized — see `CdkScrollable.scrollTo`.
- `scrollToTop()`: `void` — Scrolls to the start of the vertical axis.
- `scrollToBottom()`: `void` — Scrolls to the end of the vertical axis.
- `scrollStart()`: `void` — Scrolls to the logical start of the horizontal axis — the right edge in RTL, left in LTR.
- `scrollEnd()`: `void` — Scrolls to the logical end of the horizontal axis — the left edge in RTL, right in LTR.
- `scrollToElement()`: `void` — Scrolls `target` (an element, or a selector resolved against this viewport) into view.
- `scrollIntoView()`: `void` — Scrolls `target` to the center of the viewport.
- `getNativeElement()`: `HTMLElement` — The viewport's native scrollable element — the host this directive is applied to.

## Functions

### kbqNativeScrollbarOptionsProvider (function)

Overrides the default native scrollbar options within the given injector scope.

```ts
function kbqNativeScrollbarOptionsProvider(
    options: Partial<KbqNativeScrollbarOptions>
): Provider;
```

### kbqScrollbarOptionsProvider (function)

Overrides the default scrollbar options within the given injector scope.

```ts
function kbqScrollbarOptionsProvider(
    options: Partial<KbqScrollbarOptions>
): Provider;
```

## Types

### KbqNativeScrollbarOptions (type)

Configuration for `KbqNativeScrollbar`.

```ts
type KbqNativeScrollbarOptions = {
    descendants: boolean;
};
```

- `descendants`: `boolean` — Whether browser-rendered scrollbars of descendant elements should also be customized.

### KbqScrollbarMode (type)

How the scrollbar is presented:
- `hover` — track appears on pointer hover or while scrolling (default);
- `always` — track is always visible while the content overflows;
- `native` — the browser's native scrollbar is used;
- `hidden` — no scrollbar is shown, but the content stays scrollable.

`hover` and `always` draw a bar only for an axis the user can scroll: one whose computed `overflow` is
`hidden`, `clip` or `visible` gets none, however far its content overflows.

```ts
type KbqScrollbarMode = 'always' | 'hidden' | 'hover' | 'native';
```

### KbqScrollbarOptions (type)

Configuration for `KbqScrollbar`.

```ts
type KbqScrollbarOptions = {
    mode: KbqScrollbarMode;
    hideDelay: number;
};
```

- `hideDelay`: `number` — How long the scroll-revealed track stays visible after scrolling stops, in milliseconds.

### KbqScrollbarScrollToElementOptions (type)

Options accepted by `KbqScrollbarViewport.scrollToElement`/`KbqScrollbar.scrollToElement`.

```ts
type KbqScrollbarScrollToElementOptions = {
    top?: number;
    left?: number;
    behavior?: ScrollBehavior;
};
```

- `top?`: `number` — Extra gap to leave above the target, in px — e.g. so it doesn't end up under a sticky header.
- `left?`: `number` — Extra gap to leave to the left of the target, in px.

### KbqScrollbarScrollToOptions (type)

Options accepted by `KbqScrollbarViewport.scrollTo`/`KbqScrollbar.scrollTo` — RTL-normalized, see `CdkScrollable.scrollTo`.

```ts
type KbqScrollbarScrollToOptions = ExtendedScrollToOptions;
```

## Constants

### KBQ_NATIVE_SCROLLBAR_OPTIONS (const)

Injection token holding the current `KbqNativeScrollbarOptions`.

```ts
const KBQ_NATIVE_SCROLLBAR_OPTIONS: InjectionToken<KbqNativeScrollbarOptions>;
```

### KBQ_SCROLLBAR_OPTIONS (const)

Injection token holding the current `KbqScrollbarOptions`.

```ts
const KBQ_SCROLLBAR_OPTIONS: InjectionToken<KbqScrollbarOptions>;
```
