feat(Row): add click event (#4170)

This commit is contained in:
neverland 2019-08-21 10:23:05 +08:00 committed by GitHub
parent 6b8fbfb290
commit 71501d0ac1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 0 deletions

View File

@ -107,6 +107,12 @@ Setting `type` to `flex` to enable flex layout
| offset | number of spacing on the left side of the grid | `string | number` | - |
| tag | Custom element tag | `string` | `div` |
### Row Events
| Event | Description | Arguments |
|------|------|------|
| click | Triggered when click row | event: Event |
### Col Events
| Event | Description | Arguments |

View File

@ -110,6 +110,12 @@ Layout 组件提供了`24列栅格`,通过在`Col`上添加`span`属性设置
| offset | 列元素偏移距离 | `string | number` | - | - |
| tag | 自定义元素标签 | `string` | `div` | - |
### Row Events
| 事件名 | 说明 | 回调参数 |
|------|------|------|
| click | 点击时触发 | event: Event |
### Col Events
| 事件名 | 说明 | 回调参数 |

View File

@ -1,4 +1,5 @@
import Col from '..';
import Row from '../../row';
import { mount } from '../../../test/utils';
test('Col click event', () => {
@ -7,3 +8,10 @@ test('Col click event', () => {
expect(wrapper.emitted('click')).toBeTruthy();
});
test('Row click event', () => {
const wrapper = mount(Row);
wrapper.trigger('click');
expect(wrapper.emitted('click')).toBeTruthy();
});

View File

@ -17,6 +17,12 @@ export default createComponent({
}
},
methods: {
onClick(event) {
this.$emit('click', event);
}
},
render() {
const { align, justify } = this;
const flex = this.type === 'flex';
@ -31,6 +37,7 @@ export default createComponent({
[`align-${align}`]: flex && align,
[`justify-${justify}`]: flex && justify
})}
onClick={this.onClick}
>
{this.slots()}
</this.tag>