# API of `@koobiq/components/navbar`

Documented on [Navbar](https://koobiq.io/en/components/navbar.md). NgModule: `KbqNavbarModule`.

## Components

### KbqNavbar (component)

```ts
@Component({ selector: 'kbq-navbar' })
class KbqNavbar extends KbqFocusableComponent {
    readonly ariaLabel = input<string | null>(null, {
        alias: 'aria-label'
    });
    readonly localeConfiguration: Signal<KbqNavbarLocaleConfiguration>;
}
```

- `[localeOverrides]`: `KbqPartialLocaleData | undefined` — Localized strings for this element and its subtree, keyed by locale section. Every key is optional at
  every depth.
- `[aria-label]`: `string | null` — Accessible name of the navigation landmark. Set it whenever a page renders more than one navbar, so
  assistive technology can tell them apart.
- `localeConfiguration`: `Signal<KbqNavbarLocaleConfiguration>` — Localized strings of the navbar, the accessible name of the «More» trigger among them, see
  `KbqNavbarLocaleConfiguration`.

### KbqNavbarBrand (component)

```ts
@Component({
    selector: 'kbq-navbar-brand, [kbq-navbar-brand]',
    exportAs: 'kbqNavbarBrand'
})
class KbqNavbarBrand {
    readonly collapsedText = input<string>('');
    readonly tooltipDisabled = input<boolean | undefined>(undefined, {
        alias: 'kbqTooltipDisabled'
    });
    readonly ariaLabel = input<string | null>(null, {
        alias: 'aria-label'
    });
    get isLink(): boolean;
}
```

- `[collapsedText]`: `string` — text that will be displayed in the tooltip. By default, the text is taken from kbq-navbar-title.
- `[kbqTooltipDisabled]`: `boolean | undefined` — Explicitly enables or disables the brand's tooltip.

  Left unset, the tooltip is enabled exactly when the title cannot be read from the brand itself — the
  navbar is collapsed, the title is clipped, or there is no title at all.
- `[aria-label]`: `string | null` — Accessible name of the brand. Needed when the brand renders nothing but a logo.
- `isLink`: `boolean` — Whether the brand is rendered as a native link.

### KbqNavbarItem (component)

```ts
@Component({
    selector: 'kbq-navbar-item, [kbq-navbar-item]',
    exportAs: 'kbqNavbarItem'
})
class KbqNavbarItem {
    readonly collapsedText = input<string>('');
    readonly collapsable = input<boolean>(true);
    readonly tooltipDisabled = input<boolean | undefined>(undefined, {
        alias: 'kbqTooltipDisabled'
    });
    readonly ariaLabel = input<string | null>(null, {
        alias: 'aria-label'
    });
    readonly isCollapsed: Signal<boolean>;
    set collapsed(value: boolean);
    get titleText(): string | null;
}
```

- `[collapsedText]`: `string` — Text shown in the tooltip of a collapsed item, and in the row an icon-only item renders in the «More» panel
  (where it wins over `aria-label` and the tooltip text). Defaults to the text of the projected
  `kbq-navbar-title`.
- `[collapsable]`: `boolean` — Whether the item may be collapsed when the horizontal navbar runs out of room.
- `[kbqTooltipDisabled]`: `boolean | undefined` — Explicitly enables or disables the item's tooltip.

  Left unset, the tooltip is enabled exactly when the title cannot be read from the item itself — the item
  is collapsed, its title is clipped, or it has no title at all.
- `[aria-label]`: `string | null` — Accessible name of the item. Needed for an icon-only item, which has no visible label of its own; an
  item that renders a title is named by it.
- `isCollapsed`: `Signal<boolean>` — Whether the item is rendered in its collapsed (icon-only) form.
- `collapsed`: `boolean` — Collapses the item regardless of what the ambient navbar decided. The class is written here rather than
  only through the host binding: the navbar's fit measures the layout in the same pass it collapses items
  in, and a binding reaches the DOM only at the next change detection.
- `titleText`: `string | null` — Text used for the tooltip and for the accessible name of a collapsed item.

### KbqNavbarToggle (component)

```ts
@Component({ selector: 'kbq-navbar-toggle, [kbq-navbar-toggle]' })
class KbqNavbarToggle {
    toggle(): void;
}
```

- `toggle()`: `void` — toggles the state of the navbar

### KbqVerticalNavbar (component)

```ts
@Component({ selector: 'kbq-vertical-navbar', exportAs: 'KbqVerticalNavbar' })
class KbqVerticalNavbar extends KbqFocusableComponent {
    readonly openOver = input<boolean>(false);
    readonly expanded = model<boolean>(false);
    readonly ariaLabel = input<string | null>(null, {
        alias: 'aria-label'
    });
    readonly localeConfiguration: Signal<KbqNavbarLocaleConfiguration>;
    toggle(): void;
}
```

- `[openOver]`: `boolean` — Whether the expanded navbar overlays the page content instead of taking room from it.
- `[(expanded)]`: `boolean` — Whether the navbar is expanded.
- `[localeOverrides]`: `KbqPartialLocaleData | undefined` — Localized strings for this element and its subtree, keyed by locale section. Every key is optional at
  every depth.
- `[aria-label]`: `string | null` — Accessible name of the navigation landmark. Set it whenever a page renders more than one navbar, so
  assistive technology can tell them apart.
- `localeConfiguration`: `Signal<KbqNavbarLocaleConfiguration>` — Localized strings of the navbar.

  A signal, so that a locale change reaches the `OnPush` descendants that render these strings — a plain
  field would leave them showing the previous locale until something else marked them dirty. It also keeps
  the value observable from outside: `KbqNavbarToggle` reads it in an `effect` to refresh its tooltip,
  which a `markForCheck()` here could never have reached in that separate `OnPush` view.
- `toggle()`: `void` — Expands a collapsed navbar and collapses an expanded one.

## Directives

### KbqFocusableComponent (directive)

```ts
@Directive()
class KbqFocusableComponent {
    readonly ariaLabel = input<string | null>(null, {
        alias: 'aria-label'
    });
}
```

- `[aria-label]`: `string | null` — Accessible name of the navigation landmark. Set it whenever a page renders more than one navbar, so
  assistive technology can tell them apart.

### KbqNavbarBento (directive)

```ts
@Directive({ selector: 'kbq-navbar-item[bento], [kbq-navbar-item][bento]' })
class KbqNavbarBento {}
```

### KbqNavbarContainer (directive)

```ts
@Directive({ selector: 'kbq-navbar-container, [kbq-navbar-container]' })
class KbqNavbarContainer {}
```

### KbqNavbarDivider (directive)

```ts
@Directive({ selector: 'kbq-navbar-divider' })
class KbqNavbarDivider {}
```

### KbqNavbarFocusableItem (directive)

```ts
@Directive({
    selector: 'kbq-navbar-item, [kbq-navbar-item], kbq-navbar-brand, [kbq-navbar-brand], kbq-navbar-toggle'
})
class KbqNavbarFocusableItem implements IFocusableOption {
    disabled = input<boolean | undefined>();
    get nestedElement(): KbqNavbarNestedElement | undefined;
    set hasFocus(value: boolean);
}
```

- `[disabled]`: `boolean | undefined` — Whether the item is disabled. Also `true` for a decorative element and for one hidden under the «More» panel
  of a horizontal navbar, which the key manager skips as well.
- `nestedElement`: `KbqNavbarNestedElement | undefined` — Interactive element projected into the item, if any.

### KbqNavbarItemContent (directive)

Marks arbitrary content of a navbar item that takes the spot of the item icon.

The navbar reserves a 40×40px square for the content and leaves the positioning inside the square to the
content itself: it can fill the whole square or render smaller with its own paddings. The square size is
controlled by the `--kbq-navbar-item-size-custom-content-width` and `--kbq-navbar-item-size-custom-content-height`
tokens.

```ts
@Directive({ selector: '[kbqNavbarItemContent]' })
class KbqNavbarItemContent {}
```

### KbqNavbarItemSuffix (directive)

Marks content to be projected after the title of a navbar item.

```ts
@Directive({ selector: '[kbqNavbarItemSuffix]' })
class KbqNavbarItemSuffix {}
```

### KbqNavbarLogo (directive)

```ts
@Directive({ selector: 'kbq-navbar-logo, [kbq-navbar-logo]' })
class KbqNavbarLogo {}
```

### KbqNavbarRectangleElement (directive)

```ts
@Directive({
    selector: 'kbq-navbar-item, [kbq-navbar-item], kbq-navbar-divider, kbq-navbar-brand, [kbq-navbar-brand]'
})
class KbqNavbarRectangleElement implements KbqOverflowFitItem {
    readonly alwaysVisible = input<boolean>(false);
    orientation: KbqNavbarOrientation;
    set collapsed(value: boolean);
    getOuterElementWidth(): number;
}
```

- `[alwaysVisible]`: `boolean` — Element with this attribute is never hidden under the «More» panel of a horizontal navbar, whatever the
  overflow. Defaults to `false`.
- `orientation`: `KbqNavbarOrientation` — Orientation of the navbar this element belongs to. Written by the ambient `KbqNavbar` /
  `KbqVerticalNavbar`; the element itself only reads it.
- `getOuterElementWidth()`: `number` — Outer width of the element: its border box plus horizontal margins.

### KbqNavbarTitle (directive)

```ts
@Directive({ selector: 'kbq-navbar-title, [kbq-navbar-title]' })
class KbqNavbarTitle {
    get text(): string;
    get isOverflown(): boolean;
    get isClamped(): boolean;
    getOuterElementWidth(): number;
}
```

- `text`: `string` — Text content of the title element.
- `isOverflown`: `boolean` — Whether the text is clipped horizontally (e.g. by `text-overflow: ellipsis`).
- `isClamped`: `boolean` — Whether the text is clipped vertically (e.g. by `-webkit-line-clamp`).

  Kept separate from `isOverflown` on purpose: wrapped text never exceeds its width, so only this
  check catches a clamped title. `isOverflown` is also read by `KbqNavbarItem`, whose titles are
  always `nowrap` — folding the two together would let sub-pixel line-height rounding enable
  tooltips on every navbar item.
- `getOuterElementWidth()`: `number` — Outer width of the title: its border box plus horizontal margins.

## Types

### KbqNavbarItemTrigger (interface)

A custom interactive component projected into a navbar item in place of a button or a form field.

Provide the component's own class as `KBQ_NAVBAR_ITEM_TRIGGER`, and the item hands keyboard focus and
activation to it: it gets no synthetic click, stays the single tab stop of the navbar, and keeps working
with arrow-key navigation. The component owns its overlay — a dropdown, a popover, or anything else — and
must not be reachable by Tab on its own (`tabindex` stays with the navbar, which moves focus between items
with the arrow keys).

The item paints its hover, pressed, selected and keyboard-focus states around the component, so the
component styles only its content and must not add a focus outline of its own.

```ts
interface KbqNavbarItemTrigger {
    readonly hasFocus: boolean;
    focus(): void;
    focusViaKeyboard?(): void;
}
```

- `hasFocus`: `boolean` — Whether the component currently holds focus.
- `focus()`: `void` — Moves focus into the component.
- `focusViaKeyboard?()`: `void` — Moves focus into the component as if it was reached with the keyboard — the focused element shows its
  keyboard focus state.

### KbqNavbarNestedElement (type)

Interactive content a navbar item recognizes as owning the interaction: a projected button or form field,
or a custom component provided as `KBQ_NAVBAR_ITEM_TRIGGER`.

```ts
type KbqNavbarNestedElement = KbqButton | KbqFormField | KbqNavbarItemTrigger;
```

### KbqNavbarOrientation (type)

Orientation of the navbar an element belongs to.

```ts
type KbqNavbarOrientation = 'horizontal' | 'vertical';
```

## Constants

### KBQ_NAVBAR_ITEM_TRIGGER (const)

Makes a custom component projected into a navbar item the owner of the item's interaction.

```ts
const KBQ_NAVBAR_ITEM_TRIGGER: InjectionToken<KbqNavbarItemTrigger>;
```

### KBQ_VERTICAL_NAVBAR_CONFIGURATION (const)

Deprecated: Use `KBQ_NAVBAR_LOCALE_CONFIGURATION`. Will be removed in 22.0.0.

```ts
const KBQ_VERTICAL_NAVBAR_CONFIGURATION: InjectionToken<KbqNavbarLocaleConfiguration>;
```

### KBQ_VERTICAL_NAVBAR_DEFAULT_CONFIGURATION (const)

Deprecated: Use `KBQ_NAVBAR_DEFAULT_LOCALE_CONFIGURATION`. Will be removed in 22.0.0.

```ts
const KBQ_VERTICAL_NAVBAR_DEFAULT_CONFIGURATION: KbqNavbarLocaleConfiguration;
```

### kbqNavbarLocaleConfigurationProvider (const)

Utility provider for `KBQ_NAVBAR_LOCALE_CONFIGURATION`. Only the strings you pass are overridden; the
rest keep following the active locale.

```ts
const kbqNavbarLocaleConfigurationProvider: (
    configuration: KbqDeepPartial<KbqNavbarLocaleConfiguration>
) => Provider;
```
