Skip to content

Commit 241bdf7

Browse files
committed
feat(container): auto detect ion-content and handle scrolling
docs(container): document noScroll attribute
1 parent 657622d commit 241bdf7

File tree

4 files changed

+59
-5
lines changed

4 files changed

+59
-5
lines changed

Diff for: angular/src/directives/proxies.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { ProxyCmp, proxyOutputs } from './proxies-utils';
66
import { Components } from '@ionic-super-tabs/core';
77

88
export declare interface SuperTab extends Components.SuperTab {}
9-
@ProxyCmp({'methods': ['getRootScrollableEl']})
10-
@Component({ selector: 'super-tab', changeDetection: ChangeDetectionStrategy.OnPush, template: '<ng-content></ng-content>' })
9+
@ProxyCmp({inputs: ['noScroll'], 'methods': ['getRootScrollableEl']})
10+
@Component({ selector: 'super-tab', changeDetection: ChangeDetectionStrategy.OnPush, template: '<ng-content></ng-content>', inputs: ['noScroll'] })
1111
export class SuperTab {
1212
protected el: HTMLElement;
1313
constructor(c: ChangeDetectorRef, r: ElementRef, protected z: NgZone) {

Diff for: core/src/components.d.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ export namespace Components {
1818
* Returns the root scrollable element
1919
*/
2020
'getRootScrollableEl': () => Promise<HTMLElement | null>;
21+
/**
22+
* Set this to true to prevent vertical scrolling of this tab. Defaults to `false`. This property will automatically be set to true if there is a direct child element of `ion-content`. To override this behaviour make sure to explicitly set this property to `false`.
23+
*/
24+
'noScroll': boolean;
2125
}
2226
interface SuperTabButton {
2327
'active'?: boolean;
@@ -157,7 +161,12 @@ declare global {
157161
}
158162

159163
declare namespace LocalJSX {
160-
interface SuperTab {}
164+
interface SuperTab {
165+
/**
166+
* Set this to true to prevent vertical scrolling of this tab. Defaults to `false`. This property will automatically be set to true if there is a direct child element of `ion-content`. To override this behaviour make sure to explicitly set this property to `false`.
167+
*/
168+
'noScroll': boolean;
169+
}
161170
interface SuperTabButton {
162171
/**
163172
* Whether the button is disabled

Diff for: core/src/super-tab/readme.md

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
<!-- Auto Generated Below -->
66

77

8+
## Properties
9+
10+
| Property | Attribute | Description | Type | Default |
11+
| ----------------------- | ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- | ----------- |
12+
| `noScroll` _(required)_ | `no-scroll` | Set this to true to prevent vertical scrolling of this tab. Defaults to `false`. This property will automatically be set to true if there is a direct child element of `ion-content`. To override this behaviour make sure to explicitly set this property to `false`. | `boolean` | `undefined` |
13+
14+
815
## Methods
916

1017
### `getRootScrollableEl() => Promise<HTMLElement | null>`

Diff for: core/src/super-tab/super-tab.component.tsx

+40-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, ComponentInterface, Element, h, Method } from '@stencil/core';
1+
import { Component, ComponentInterface, Element, h, Method, Prop } from '@stencil/core';
22

33

44
@Component({
@@ -10,12 +10,46 @@ import { Component, ComponentInterface, Element, h, Method } from '@stencil/core
1010
export class SuperTabComponent implements ComponentInterface {
1111
@Element() el!: HTMLSuperTabElement;
1212

13+
/**
14+
* Set this to true to prevent vertical scrolling of this tab. Defaults to `false`.
15+
*
16+
* This property will automatically be set to true if there is
17+
* a direct child element of `ion-content`. To override this
18+
* behaviour make sure to explicitly set this property to `false`.
19+
*/
20+
@Prop({
21+
reflect: true,
22+
}) noScroll!: boolean;
23+
24+
componentDidLoad() {
25+
this.checkIonContent();
26+
}
27+
28+
componentDidUpdate() {
29+
// check for ion-content after update, in case it was dynamically loaded
30+
this.checkIonContent();
31+
}
32+
33+
/**
34+
* Check if we have an ion-content as a child and update the `noScroll` property
35+
* if it's not set yet.
36+
*/
37+
private checkIonContent() {
38+
if (typeof this.noScroll !== 'boolean') {
39+
const ionContentEl = this.el.querySelector('ion-content');
40+
41+
if (ionContentEl && ionContentEl.parentElement === this.el) {
42+
this.noScroll = true;
43+
}
44+
}
45+
}
46+
1347
/**
1448
* Returns the root scrollable element
1549
*/
1650
@Method()
1751
async getRootScrollableEl(): Promise<HTMLElement | null> {
18-
if (this.el.scrollHeight > this.el.clientHeight) {
52+
if (!this.noScroll && this.el.scrollHeight > this.el.clientHeight) {
1953
return this.el;
2054
}
2155

@@ -25,6 +59,10 @@ export class SuperTabComponent implements ComponentInterface {
2559
return ionContent.getScrollElement();
2660
}
2761

62+
if (this.noScroll) {
63+
return null;
64+
}
65+
2866
return this.el;
2967
}
3068

0 commit comments

Comments
 (0)