# AiScrollToLatest
## Description
BitAiScrollToLatest is the floating button that appears when the reader has scrolled away from the newest message of a transcript and takes them back to it. It renders only while Visible - there is somewhere to go - and floats centered above its nearest positioned ancestor, which in a BitAiChat is the footer, so it sits just above the composer whatever height the composer has. Pair it with the OnPinnedChange and ScrollToLatestAsync of a BitAiMessageList.
## Parameters
| Name | Type | Default Value | Description |
| :--- | :--- | :------------ | :---------- |
| Classes | `BitAiScrollToLatestClassStyles?` | null | Custom CSS classes for different parts of the scroll to latest. |
| Label | `string?` | null | The text of the button, which is also its accessible name, in place of the ScrollToLatest of the string table ("Scroll to latest"). |
| OnClick | `EventCallback` | | The callback for when the button is pressed - typically the ScrollToLatestAsync of the BitAiMessageList it belongs to, then moving the focus to the composer, since the button goes away. Not raised while the button is disabled. |
| Styles | `BitAiScrollToLatestClassStyles?` | null | Custom CSS styles for different parts of the scroll to latest. |
| Visible | `bool` | false | Shows the button - while the reader is away from the newest message, so it never sits over the transcript doing nothing. Left unset, nothing is rendered. |
| AriaLabel | `string?` | null | Gets or sets the accessible label for the component, used by assistive technologies. |
| Class | `string?` | null | Gets or sets the CSS class name(s) to apply to the rendered element. |
| Dir | `BitDir?` | null | Gets or sets the text directionality for the component's content. |
| Disabled | `bool` | false | Gets or sets a value indicating whether the component is disabled and cannot respond to user interaction. |
| ForceAnimation | `bool` | false | Gets or sets a value indicating whether the component's animations play at their full duration even when reduced motion is requested. |
| HtmlAttributes | `Dictionary<string, object>` | new Dictionary<string, object>() | Captures additional HTML attributes to be applied to the rendered element, in addition to the component's parameters. An attribute written on the component wins over an entry of the same name. |
| Id | `string?` | null | Gets or sets the unique identifier for the component's root element. |
| Style | `string?` | null | Gets or sets the CSS style string to apply to the rendered element. |
| TabIndex | `string?` | null | Gets or sets the tab order index for the component when navigating with the keyboard. |
| Visibility | `BitVisibility` | BitVisibility.Visible | Gets or sets the visibility state (visible, hidden, or collapsed) of the component. |
## Public Members
| Name | Type | Default Value | Description |
| :--- | :--- | :------------ | :---------- |
| UniqueId | `Guid` | Guid.NewGuid() | Gets the readonly unique identifier for the component's root element, assigned when the component instance is constructed. |
| RootElement | `ElementReference` | | Gets the reference to the root HTML element associated with this component. |
## Enums
### BitVisibility Enum
| Name | Value | Description |
| :--- | :--- | :---------- |
| Visible | 0 | The content of the component is visible. |
| Hidden | 1 | The content of the component is hidden, but the space it takes on the page remains (visibility:hidden). |
| Collapsed | 2 | The component is hidden (display:none). |
### BitDir Enum
| Name | Value | Description |
| :--- | :--- | :---------- |
| Ltr | 0 | Ltr (left to right) is to be used for languages that are written from the left to the right (like English). |
| Rtl | 1 | Rtl (right to left) is to be used for languages that are written from the right to the left (like Arabic). |
| Auto | 2 | Auto lets the user agent decide. It uses a basic algorithm as it parses the characters inside the element until it finds a character with a strong directionality, then applies that directionality to the whole element. |
## Sub Classes
### BitAiScrollToLatestClassStyles Properties
| Name | Type | Default Value | Description |
| :--- | :--- | :------------ | :---------- |
| Root | `string?` | null | Custom CSS classes/styles for the root element of the BitAiScrollToLatest. |
| Button | `BitButtonClassStyles?` | null | Custom CSS classes/styles for the button of the BitAiScrollToLatest. |
## CSS Variables
Public CSS custom properties read off the component's root. Set one on `:root` to restyle every instance, on any ancestor to restyle the ones inside it, or on the `Style` of one instance to restyle it and every instance nested inside it, which inherits the value too - a parameter changes one alone, as does the real CSS property on its `Style` / `Styles` when that property does not inherit (`opacity`); an inherited one (`color`, `font-family`) reaches the nested instances that do not set it themselves.
| Name | Default Value | Description |
| :--- | :------------ | :---------- |
| `--bit-AiScrollToLatest-offset` | spacing(1) | Room between the button and the top edge of the positioned box it floats above. |
| `--bit-AiScrollToLatest-shadow` | var(--bit-shd-popup) | Elevation of the button over the transcript. |
| `--bit-AiScrollToLatest-z-index` | 3 | Stacking of the button over the transcript. |
## Examples
\n**Basic**:
```razor
The positioned box it floats above, such as the footer of a chat.
The footer of the transcript.
```
```csharp
private BitAiMessageList? list;
private bool isPinned = true;
// A conversation long enough to scroll.
private readonly BitAiConversation conversation = AiDemoConversations.Long(20);
private void HandlePinnedChange(bool pinned)
{
isPinned = pinned;
}
private async Task ScrollToLatest()
{
if (list is not null) await list.ScrollToLatestAsync();
}
```
\n**Label**:
```razor
```
\n**Disabled**:
```razor
```
\n**Cascading parameters**:
```razor
```
```csharp
private readonly BitAiScrollToLatestParams[] scrollParams = [new() { Label = "Back to the newest message" }];
```
\n**Style & Class**:
```razor
```
\n**RTL**:
```razor
```
Pressed @clicks times.
```
```csharp
private bool isVisible = true;
private int clicks;
private void HandleClick()
{
clicks++;
}
```
\n**With a message list**:
```razor