diff --git a/components/tag/PropsType.tsx b/components/tag/PropsType.tsx index 65e7d5068..0412cbc14 100644 --- a/components/tag/PropsType.tsx +++ b/components/tag/PropsType.tsx @@ -6,4 +6,5 @@ export interface TagPropsType { onChange?: (selected: boolean) => void; onClose?: () => void; afterClose?: () => void; + onLongPress?: () => void; } diff --git a/components/tag/__tests__/index.test.native.js b/components/tag/__tests__/index.test.native.js index 02ba125be..f5db2a287 100644 --- a/components/tag/__tests__/index.test.native.js +++ b/components/tag/__tests__/index.test.native.js @@ -33,4 +33,11 @@ describe('Tag', () => { expect(afterClose).toHaveBeenCalled(); expect(wrapper.find('TouchableWithoutFeedback')).toHaveLength(0); }); + + it('onLongPress then callback', () => { + const onLongPress = jest.fn(); + const wrapper = shallow(Basic); + wrapper.find('TouchableWithoutFeedback').at(0).simulate('longPress'); + expect(onLongPress).toHaveBeenCalledWith(); + }); }); diff --git a/components/tag/demo/basic.native.tsx b/components/tag/demo/basic.native.tsx index f3d8fc2db..108f51000 100644 --- a/components/tag/demo/basic.native.tsx +++ b/components/tag/demo/basic.native.tsx @@ -33,6 +33,14 @@ export default class BasicTagExample extends React.Component { Small and Readonly + + { + console.log('onLongPress'); + }} + > + LongPress + ); } diff --git a/components/tag/index.en-US.md b/components/tag/index.en-US.md index 4ce062141..d63d2ffbf 100644 --- a/components/tag/index.en-US.md +++ b/components/tag/index.en-US.md @@ -21,3 +21,4 @@ Properties | Descrition | Type | Default | onChange | The callback function that is triggered when the selected state changes. | (selected: bool): void | - | | onClose | The callback function that is triggered when the tag is closed. | (): void | - | | afterClose | The callback function that is triggered after close. | (): void | - | +| onLongPress | The callback function that is triggered when the tag is long pressed. | (): void | - | \ No newline at end of file diff --git a/components/tag/index.native.tsx b/components/tag/index.native.tsx index 55c02001f..5f1ce6d92 100644 --- a/components/tag/index.native.tsx +++ b/components/tag/index.native.tsx @@ -28,6 +28,7 @@ export default class Tag extends React.Component { onClose() {}, afterClose() {}, onChange() {}, + onLongPress() {}, styles: TagStyles, }; @@ -68,6 +69,16 @@ export default class Tag extends React.Component { ); } + handleLongPress = () => { + const { disabled, onLongPress } = this.props; + if (disabled) { + return; + } + if (onLongPress) { + onLongPress(); + } + } + onTagClose = () => { if (this.props.onClose) { this.props.onClose(); @@ -158,7 +169,7 @@ export default class Tag extends React.Component { return !this.state.closed ? ( - + {children}{' '} diff --git a/components/tag/index.zh-CN.md b/components/tag/index.zh-CN.md index f7d5dc490..6bc90e295 100644 --- a/components/tag/index.zh-CN.md +++ b/components/tag/index.zh-CN.md @@ -21,3 +21,4 @@ subtitle: 标签 | onChange | 切换选中回调函数 | (selected: bool): void | 无 | | onClose | 点关闭时的回调函数 | (): void | 无 | | afterClose | 关闭后的回调 | (): void | 无 | +| onLongPress | 长按的回调 | (): void | 无 | \ No newline at end of file