Skip to content

Commit

Permalink
fix(module: swipe-action): fix autoclose not work bug (#282)
Browse files Browse the repository at this point in the history
  • Loading branch information
BronzeCui authored and fisherspy committed Feb 19, 2019
1 parent c533d16 commit acb180e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
1 change: 0 additions & 1 deletion components/swipe-action/demo/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { Component } from '@angular/core';
<br/>
<List>
<SwipeAction style="background-color: gray"
[autoClose]="true"
[right]="right"
[left]="left"
(onOpen)="open()"
Expand Down
2 changes: 1 addition & 1 deletion components/swipe-action/doc/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Properties | Descrition | Type | Default
-----------|------------|------|-------- |
| left | left buttons for `swipeout` | Array | `null` |
| right | right buttons for `swipeout` | Array | `null` |
| autoClose | auto hide after button is pressed | Boolean | `function() {}` |
| autoClose | auto hide after button is pressed | Boolean | `false` |
| onOpen | callback function that is triggered when the buttons will be opened | (): void | `function() {}` |
| disabled | whether is disabled | Boolean | `false` |
| onClose | callback function that is triggered when the buttons will be closed | (): void | `function() {}` |
Expand Down
2 changes: 1 addition & 1 deletion components/swipe-action/doc/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ subtitle: 滑动操作
----|-----|------|------ |
| left | 左侧按钮组 | Array | `null` |
| right | 右侧按钮组 | Array | `null` |
| autoClose | 点击按钮后自动隐藏按钮 | Boolean | `function() {}` |
| autoClose | 点击按钮后自动隐藏按钮 | Boolean | `false` |
| onOpen | 打开时回调函数 | (): void | `function() {}` |
| disabled | 禁用 `swipeout` | Boolean | `false` |
| onClose | 关闭时回调函数 | (): void | `function() {}` |
Expand Down
8 changes: 8 additions & 0 deletions components/swipe-action/swipe-action.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ describe('swipeAction', () => {
fixture.detectChanges();
expect(component.onClose).toHaveBeenCalledTimes(0);
});

it('btnLength correct when btnRef is null', () => {
component.swipeAction.leftBtnRef = null;
component.swipeAction.rightBtnRef = null;
component.swipeAction.ngAfterViewInit();
expect(component.swipeAction._btnsLeftWidth).toEqual(0);
expect(component.swipeAction._btnsRightWidth).toEqual(0);
});
});

@Component({
Expand Down
10 changes: 6 additions & 4 deletions components/swipe-action/swipe-action.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
ViewEncapsulation
} from '@angular/core';


@Component({
selector: 'SwipeAction, nzm-swipe-action',
templateUrl: './swipe-action.component.html',
Expand Down Expand Up @@ -60,11 +59,14 @@ export class SwipeAction implements OnInit, AfterViewInit, OnDestroy {
};
}

onCloseSwipe = () => {
onCloseSwipe = (ev) => {
if (!(this._openedLeft || this._openedRight)) {
return;
}
this.close();
const pNode = ev.target.closest(`.${this.prefixCls}-actions`)
if (!pNode) {
this.close();
}
};

close() {
Expand All @@ -88,7 +90,7 @@ export class SwipeAction implements OnInit, AfterViewInit, OnDestroy {
return Math.abs(value) - Math.abs(limit) > 0 ? limit : value;
}

onTouchStart = e => {
onTouchStart(e) {
this._startX = e.changedTouches[0].clientX;
this._swiping = true;
};
Expand Down

1 comment on commit acb180e

@Guoyuanqiang
Copy link
Member

Choose a reason for hiding this comment

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

close #278

Please sign in to comment.