Skip to content

Commit

Permalink
feat(item-sliding): add open method
Browse files Browse the repository at this point in the history
  • Loading branch information
shreeshbhat committed Apr 6, 2019
1 parent 77c980b commit 5444c93
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion angular/src/directives/proxies.ts
Expand Up @@ -413,7 +413,7 @@ export class IonItemSliding {
proxyOutputs(this, this.el, ['ionDrag']);
}
}
proxyMethods(IonItemSliding, ['getOpenAmount', 'getSlidingRatio', 'close', 'closeOpened']);
proxyMethods(IonItemSliding, ['getOpenAmount', 'getSlidingRatio', 'open', 'close', 'closeOpened']);
proxyInputs(IonItemSliding, ['disabled']);

export declare interface IonLabel extends StencilComponents<'IonLabel'> {}
Expand Down
1 change: 1 addition & 0 deletions core/api.txt
Expand Up @@ -471,6 +471,7 @@ ion-item-sliding,method,close,close() => Promise<void>
ion-item-sliding,method,closeOpened,closeOpened() => Promise<boolean>
ion-item-sliding,method,getOpenAmount,getOpenAmount() => Promise<number>
ion-item-sliding,method,getSlidingRatio,getSlidingRatio() => Promise<number>
ion-item-sliding,method,open,open() => Promise<void>
ion-item-sliding,event,ionDrag,void,true

ion-item,shadow
Expand Down
4 changes: 4 additions & 0 deletions core/src/components.d.ts
Expand Up @@ -1978,6 +1978,10 @@ export namespace Components {
* Get the ratio of the open amount of the item compared to the width of the options. If the number returned is positive, then the options on the right side are open. If the number returned is negative, then the options on the left side are open. If the absolute value of the number is greater than 1, the item is open more than the width of the options.
*/
'getSlidingRatio': () => Promise<number>;
/**
* Open the sliding item.
*/
'open': () => Promise<void>;
}
interface IonItemSlidingAttributes extends StencilHTMLAttributes {
/**
Expand Down
15 changes: 15 additions & 0 deletions core/src/components/item-sliding/item-sliding.tsx
Expand Up @@ -116,6 +116,21 @@ export class ItemSliding implements ComponentInterface {
return Promise.resolve(this.getSlidingRatioSync());
}

/**
* Open the sliding item.
*/
@Method()
async open() {
const options = this.el.querySelector('ion-item-options');
if (options) {
options.style.display = 'flex';
const width = options.offsetWidth;
openSlidingItem = this.el;
options.style.display = '';
this.setOpenAmount(width, true);
}
}

/**
* Close the sliding item. Items can also be closed from the [List](../../list/List).
*/
Expand Down
10 changes: 10 additions & 0 deletions core/src/components/item-sliding/readme.md
Expand Up @@ -692,6 +692,16 @@ Type: `Promise<number>`



### `open() => Promise<void>`

Open the sliding item.

#### Returns

Type: `Promise<void>`




----------------------------------------------

Expand Down
6 changes: 6 additions & 0 deletions core/src/components/item-sliding/test/basic/index.html
Expand Up @@ -38,6 +38,7 @@
<ion-button expand="block" onclick="toggleSliding()">Toggle sliding</ion-button>
<ion-button expand="block" onclick="toggleDynamicOptions()">Toggle Dynamic Options</ion-button>
<ion-button expand="block" onclick="closeOpened()">Close Opened Items</ion-button>
<ion-button expand="block" onclick="openItem()">Open Item</ion-button>
</div>

<ion-list id="list">
Expand Down Expand Up @@ -367,6 +368,11 @@ <h2>Normal button (no sliding)</h2>
list.closeSlidingItems();
}

function openItem() {
var item = document.getElementById('item0');
item.open();
}

function noclose(item) {
var itemEle = document.getElementById(item);
console.log('no close', itemEle);
Expand Down
6 changes: 6 additions & 0 deletions core/src/components/item-sliding/test/preview/index.html
Expand Up @@ -32,6 +32,7 @@
<ion-button expand="block" onclick="toggleSliding()">Toggle sliding</ion-button>
<ion-button expand="block" onclick="toggleDynamicOptions()">Toggle Dynamic Options</ion-button>
<ion-button expand="block" onclick="closeOpened()">Close Opened Items</ion-button>
<ion-button expand="block" onclick="openItem()">Open Item</ion-button>
</div>

<ion-list id="list">
Expand Down Expand Up @@ -356,6 +357,11 @@ <h2>Normal button (no sliding)</h2>
list.closeSlidingItems();
}

function openItem() {
var item = document.getElementById('item0');
item.open();
}

function noclose(item) {
var itemEle = document.getElementById(item);
console.log('no close', itemEle);
Expand Down

0 comments on commit 5444c93

Please sign in to comment.