Skip to content

Commit

Permalink
feat(tabs): support swipeable
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeJim committed Jul 19, 2022
1 parent 91e86c9 commit f058b1f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/tabs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ animation | Object | - | 动画效果设置。其中 duration 表示动画时长
external-classes | Array | - | 组件类名,分别用于设置 组件外层元素、选项卡单项、选项卡激活态、滚动条样式类名 等类名。`['t-class', 't-class-item', 't-class-active', 't-class-track']` | N
placement | String | top | 选项卡位置。可选项:left/top | N
show-bottom-line | Boolean | true | 是否展示底部激活线条 | N
swipeable | Boolean | true | 是否可以滑动切换 | N
value | String / Number | - | 激活的选项卡值。TS 类型:`TabValue` `type TabValue = string | number`[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/tabs/type.ts) | N
default-value | String / Number | undefined | 激活的选项卡值。非受控属性。TS 类型:`TabValue` `type TabValue = string | number`[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/tabs/type.ts) | N

Expand Down
11 changes: 7 additions & 4 deletions src/tabs/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,19 @@ const props: TdTabsProps = {
type: Boolean,
value: true,
},
/** 是否可以滑动切换 */
swipeable: {
type: Boolean,
value: true,
},
/** 激活的选项卡值 */
value: {
type: String,
optionalTypes: [Number],
type: null,
value: null,
},
/** 激活的选项卡值,非受控属性 */
defaultValue: {
type: String,
optionalTypes: [Number],
type: null,
},
};

Expand Down
6 changes: 3 additions & 3 deletions src/tabs/tab-panel-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ const props: TdTabPanelProps = {
type: Boolean,
value: false,
},
/** 选项卡名称,可自定义选项卡导航内容 */
/** 选项卡名称 */
label: {
type: String,
value: '',
},
/** 用于自定义选项卡面板内容 */
panel: {
type: String,
},
/** 选项卡的值,唯一标识 */
value: {
type: String,
optionalTypes: [Number],
type: null,
},
};

Expand Down
6 changes: 6 additions & 0 deletions src/tabs/tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,20 @@ export default class Tabs extends SuperComponent {
}

onTouchStart(event: any) {
if (!this.properties.swipeable) return;

this.touchStart(event);
}

onTouchMove(event: any) {
if (!this.properties.swipeable) return;

this.touchMove(event);
}

onTouchEnd() {
if (!this.properties.swipeable) return;

const { direction, deltaX, offsetX } = this;
const minSwipeDistance = 50;
if (direction === 'horizontal' && offsetX >= minSwipeDistance) {
Expand Down
20 changes: 13 additions & 7 deletions src/tabs/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,26 @@ export interface TdTabsProps {
type: BooleanConstructor;
value?: boolean;
};
/**
* 是否可以滑动切换
* @default true
*/
swipeable?: {
type: BooleanConstructor;
value?: boolean;
};
/**
* 激活的选项卡值
*/
value?: {
type: StringConstructor;
optionalTypes: Array<NumberConstructor>;
type: null;
value?: TabValue;
};
/**
* 激活的选项卡值,非受控属性
*/
defaultValue?: {
type: StringConstructor;
optionalTypes: Array<NumberConstructor>;
type: null;
value?: TabValue;
};
}
Expand All @@ -71,7 +77,8 @@ export interface TdTabPanelProps {
value?: boolean;
};
/**
* 选项卡名称,可自定义选项卡导航内容
* 选项卡名称
* @default ''
*/
label?: {
type: StringConstructor;
Expand All @@ -88,8 +95,7 @@ export interface TdTabPanelProps {
* 选项卡的值,唯一标识
*/
value?: {
type: StringConstructor;
optionalTypes: Array<NumberConstructor>;
type: null;
value?: TabValue;
};
}
Expand Down

0 comments on commit f058b1f

Please sign in to comment.