Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
MurhafSousli committed Sep 26, 2024
1 parent ef964b1 commit 72ac305
Show file tree
Hide file tree
Showing 40 changed files with 2,313 additions and 34 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 16.0.0

- fix: `asyncDetection` scrollbars rendering delay.

## 16.0.0-beta.2

- feat: `scrollViewport` directive can be a descent child, not necessarily a direct child of `<ng-scrollbar externalViewport>`.
Expand All @@ -19,6 +23,9 @@
### Breaking changes

- Minimum compatibility is Angular v17.3.0
- The directive `cdkVirtualScrollViewport` no longer accepts `auto` value, instead use `syncSpacer`
* Before `<ng-scrollbar externalViewport cdkVirtualScrollViewport="auto">`
* After `<ng-scrollbar externalViewport cdkVirtualScrollViewport syncSpacer>`

## 15.1.3

Expand Down
40 changes: 33 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,55 @@

Custom overlay-scrollbars with native scrolling mechanism for Angular, it also provides a cross-browser smooth scroll directive.

___

### The documentation is available at the [wiki page](https://github.com/MurhafSousli/ngx-scrollbar/wiki) 📚

___
***

## Features

- Exceptional performance, see [comparing test results](https://github.com/MurhafSousli/ngx-scrollbar/wiki/Performance-analysis).
- Native scrolling mechanism.
- Easily Customizable using CSS variables.
- Easy integration with other libraries.
- Easy integration with 3rd party libraries.
- RTL support.
- Mobile support.
- SSR support.

#### Addons directives:

- Smooth scroll functionality.
- Scroll reached events.
- Scroll reached & dropped events.
- **MatSelect** integration.
- **CdkVirtualScroll** integration.

***

## Documentations

### Table of contents

* [Usage](projects/ngx-scrollbar/docs/Usage.md)
* [Styling](projects/ngx-scrollbar/docs/Styling.md)
* [Global Options](projects/ngx-scrollbar/docs/Global-options.md)
* [Smooth Scroll Functions](projects/ngx-scrollbar/docs/Smooth-Scroll-Functions.md)
* [Scroll Timeline Polyfill](projects/ngx-scrollbar/docs/Scroll-timeline-polyfill.md)

### Addons:

* [Integration Examples](projects/ngx-scrollbar/docs/Integration.md)
* [Material Select](projects/ngx-scrollbar/docs/Integration.md#material-select)
* [Material Dialog](projects/ngx-scrollbar/docs/Integration.md#material-dialog)
* [CDK Virtual Scroll](projects/ngx-scrollbar/docs/Integration.md#cdk-virtual-scroll)
* [ngx-datatable table](projects/ngx-scrollbar/docs/Integration.md#ngx-datatable-table)
* [Ag-grid table](projects/ngx-scrollbar/docs/Integration.md#ag-grid-table)
* [PrimeNG Scroller](projects/ngx-scrollbar/docs/Integration.md#primeng-scroller)
* [PrimeNG Table](projects/ngx-scrollbar/docs/Integration.md#primeng-table)
* [PrimeNG Dropdown](projects/ngx-scrollbar/docs/Integration.md#primeng-dropdown)
* [PrimeNg Dropdown (Virtual Scroll)](projects/ngx-scrollbar/docs/Integration.md#primeng-dropdown-virtual-scroll)
* [Kendu UI Grid](projects/ngx-scrollbar/docs/Integration.md#kendu-ui-grid)
* [Reached & Dropped Events](projects/ngx-scrollbar/docs/Reached-&-Dropped-Events.md)
* [Smooth Scroll Functions (without NgScrollbar)](projects/ngx-scrollbar/docs/Smooth-Scroll.md)

___


## Issues

Expand Down
42 changes: 42 additions & 0 deletions docs/v13/Global-Options-v13.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
To set global options for all scrollbar components across the app, provide the token `NG_SCROLLBAR_OPTIONS` with your custom options like in the following example:

```ts
import { NgScrollbarModule, NG_SCROLLBAR_OPTIONS } from 'ngx-scrollbar';

@NgModule({
imports: [
NgScrollbarModule
],
providers: [
{
provide: NG_SCROLLBAR_OPTIONS,
useValue: {
// ... options
}
}
]
})
```

#### Global options API (`NgScrollbarOptions`)


| Name | Default value | Description |
| --------------------------- | --------------- | -------------------------------------------------------------------- |
| **track** | `vertical` | Directions to track `horizontal`, `vertical`, `all` |
| **position** | `native` | Invert scrollbar position `native`,`invertX`,`invertY`, `invertAll` |
| **visibility** | `native` | Scrollbar visibility `native`, `hover`, `always` |
| **appearance** | `compact` | Scrollbar appearance `standard`, `compact`. |
| **viewClass** | *null* | Add custom class to the viewport element. |
| **trackClass** | *null* | Add custom class to scrollbar track elements. |
| **thumbClass** | *null* | Add custom class to scrollbar thumbnail elements. |
| **trackClickScrollDuration**| 300 | The smooth scroll duration when a scrollbar is clicked. |
| **minThumbSize** | 20 | The minimum scrollbar thumb size in px. |
| **scrollAuditTime** | 0 | Throttle scroll event in ms. |
| **windowResizeDebounce** | 0 | Debounce interval for detecting changes via `window.resize` event. |
| **sensorDebounce** | 0 | Debounce interval for detecting changes via `ResizeObserver`. |
| **sensorDisabled** | false | Whether `ResizeObserver` is disabled. |
| **pointerEventsMethod** | `viewport` | The method used to detect scrollbar pointer-events, [read more](pointer-events). |
| **pointerEventsDisabled** | false | Enable/disable the scrollbar track clicked and thumb dragged events. |
| **autoHeightDisabled** | false | Whether to set component height to content height. |
| **autoWidthDisabled** | true | Whether to set component width to content width. |
95 changes: 95 additions & 0 deletions docs/v13/Integration-v13.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
The `scrollViewport` directive allows you to use a custom viewport element in your template. It is used for integration with other libraries where the viewport can be another component or directive.

### Basic usage

```html
<ng-scrollbar>
<div scrollViewport class="custom-viewport">
<div class="scroll-content-wrapper">
<!-- content -->
</div>
</div>
</ng-scrollbar>
```

> **NOTE**: `scrollViewport` directive must be used on the direct child of `<ng-scrollbar>`
> **NOTE**: When `scrollViewport` directive is used on an element, It is recommended that its host element to have one and only one child element that acts as a content wrapper _(like `.scroll-content-wrapper` in the above example)_, this content wrapper will be used by the ResizeObserver API to observes content changes and updates the UI accordingly.
> **IMPORTANT NOTE:** Some external libraries can cause the scrollbar to recalculate very frequently when it scrolls, which can result in flickering behaviour (like the CDK virtual scroll viewport).
To avoid this, set `[autoHeightDisabled]="true"`

### Integrate with [ngx-infinite-scroll](https://github.com/orizens/ngx-infinite-scroll).

```html
<ng-scrollbar>
<div infiniteScroll [scrollWindow]="false" scrollViewport>
<mat-list>
<mat-list-item class="example-item" *ngFor="let i of array">
{{ i }}
</mat-list-item>
</mat-list>
</div>
</ng-scrollbar>
```

### Integrate with [CDK Scrollable](https://material.angular.io/cdk/scrolling/overview#cdkscrollable-and-scrolldispatcher)

If you need to get hold of the scrollable element of the component, you can add a child element and then assign it with `scrollViewport` directive

```html
<ng-scrollbar>
<div scrollViewport cdkScrollable>
<!-- CONTENT -->
</div>
</ng-scrollbar>
```

### Integrate with [CDK VirtualScroll](https://material.angular.io/cdk/scrolling/overview#virtual-scrolling).


```html
<ng-scrollbar>
<cdk-virtual-scroll-viewport itemSize="50" scrollViewport>
<div *cdkVirtualFor="let item of items">{{item}}</div>
</cdk-virtual-scroll-viewport>
</ng-scrollbar>
```

### Integrate with [CDK Drag and Drop](https://material.angular.io/cdk/drag-drop/overview)

```html
<ng-scrollbar track="horizontal" appearance="standard">

<div class="tabs"
scrollViewport
#tabDropList="cdkDropList"
dropListScroller
cdkDropList
cdkDropListLockAxis="x"
cdkDropListOrientation="horizontal"
[cdkDropListAutoScrollDisabled]="true"
(cdkDropListDropped)="drop($event)">

<div class="tab" *ngFor="let tab of tabs"
[ngClass]="{ selected: selectedTab === tab.id }"
cdkDrag
[cdkDragData]="tab"
(cdkDragStarted)="onDragStarted($event)"
(mousedown)="selectedTab = tab.id"
(click)="onSelectTab(tab)">
<span class="tab-label">{{ tab.label }}</span>
<span class="tab-close pi pi-times"></span>
</div>

</div>
</ng-scrollbar>
```
```scss
ng-scrollbar {
height: 70px;
width: 100%;
}
```

Demo: https://stackblitz.com/edit/ngx-scrollbar-cdk-drag-drop
49 changes: 49 additions & 0 deletions docs/v13/Performance-tweak-v13.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Regarding the scroll event

By default, the scroll event is used to do the necessary calculation to display the custom scrollbars.

You may want to tweak the scroll event if it is not performing well on low-end devices.

You can throttle the scroll event using the `scrollAuditTime` option, `20` milliseconds seems to be a reasonable value.

**Example:**

Set the option `[scrollAuditTime]` for a specific scrollbar component.

```html
<ng-scrollbar [scrollAuditTime]="20">
<!-- ...content... -->
</ng-scrollbar>
```

**Example:**

Set the `scrollAuditTime` option for all custom scrollbars using the global options.

```ts
import { NgScrollbarModule, NG_SCROLLBAR_OPTIONS } from 'ngx-scrollbar';

@NgModule({
imports: [
NgScrollbarModule
],
providers: [
{
provide: NG_SCROLLBAR_OPTIONS,
useValue: {
scrollAuditTime: 20
}
}
]
})
```

_This option is available in `ngx-scrollbar >= v7.1.0`_

# Regarding the `auto-height` and `auto-width` features

When any of these features is turned on, the scrollbar will re-calculate when the component size or the content size change.

If the scrollbar is used with other library that frequently changes the content or the component size, it could cause a performance issue, therefore, you should turn them off.

For example when using it with a virtual scroll library, you should set `[autoHeightDisabled]="true"` (which is already disabled by default).
69 changes: 69 additions & 0 deletions docs/v13/Pointer-Events-v13.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
The pointer-events here means the method this library use to detect the dragging of the scrollbar and the hover effect on the scrollbar

There are 2 methods to detect pointer events

```html
<ng-scrollbar pointerEventsMethod="viewport">
```

- `pointerEventsMethod="viewport"`, will detect pointer events using viewport's `mousemove`, `mousedown` and `mouseleave` events.

- `pointerEventsMethod="scrollbar"`, will detect pointer events using scrollbar `mousedown`, `mouseenter` and `mouseleave` event.

### In a nutshell, here are the pros and cons of each method with the `[appearance]` option:

<table>
<thead>
<tr>
<th>Appearance ↓</th>
<th>viewport</th>
<th>scrollbar</th>
</tr>
</thead>
<tbody>
<tr>
<td><b>Standard</b></td>
<td>
<ul>
<li><u>Only if both scrollbars appear</u>, the content may overlap under the scrollbar</li>
<li>Scrolling over scrollbar works</li>
</ul>
</td>
<td>
<ul>
<li>The content never overlap under the scrollbars</li>
<li>Scrolling over scrollbar doesn't work</li>
</ul>
</td>
</tr>
<tr>
<td><b>Compact</b></td>
<td>
<ul>
<li>Content overlaps under the scrollbar as intended</li>
<li>Scrolling over scrollbar works</li>
</ul>
</td>
<td>
<ul>
<li>The content overlaps under the scrollbar as intended</li>
<li>Scrolling over scrollbar doesn't work</li>
</ul>
</td>
</tr>
</tbody>
</table>

---

> **My recommendation:** If scrolling over scrollbar isn't a big deal, then go with `pointerEventsMethod="scrollbar"`.
---

*Theoretically `scrollbar` method is more performant because `viewport` method checks if the pointer is over the scrollbars while the pointer is moving over the viewport.*

*But most of the time, there won't be any difference in performance unless you have a complex design. try both and see what best fits your app.*

### 📌 Note

The pointer-events are disabled on mobile browsers by design. because there is no pointer 😄
22 changes: 22 additions & 0 deletions docs/v13/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## Documentation for v13

- [Demo for v13](https://ngx-scrollbar-v13.netlify.app/)
- [Usage](Usage-v13.md)
- [Styling](Styling-v13.md)
- [Global Options](Global-Options-v13.md)
- [Pointer Events](Pointer-Events-v13.md)
- [Scroll Event](scroll-event.md)
- [Updated Event](Updated-event-v13.md)
- [Smooth Scroll Functions](Smooth-scroll-functions-v13.md)
- [Performance tweak](Performance-tweak-v13.md)
- [Integration](Integration-v13.md)
- [Infinite Scroll](Integration-v13.md#integrate-with-ngx-infinite-scroll)
- [CDK Scrollable](Integration-v13.md#integrate-with-cdk-scrollable)
- [CDK Virtual Scroll](Integration-v13.md#integrate-with-cdk-virtualscroll)
- [CDK Drag and Drop](Integration-v13.md#integrate-with-cdk-drag-and-drop)
- [Reached events](reached-events-v13.md)

---

- [Smooth Scroll Module (without NgScrollbar)](Smooth-Scroll-v13.md)

Loading

1 comment on commit 72ac305

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.