[improvement] Actionsheet: add index param for select event (#2917)

This commit is contained in:
neverland 2019-03-07 20:59:46 +08:00 committed by GitHub
parent c9e578c0cf
commit bfa8f38585
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 5 deletions

View File

@ -90,7 +90,7 @@ Actionsheet will get another style if there is a `title` prop.
| Event | Description | Arguments |
|------|------|------|
| select | Triggered when click option | item |
| select | Triggered when click option | item, index |
| cancel | Triggered when cancel click | - |
### Data struct of actions

View File

@ -47,7 +47,7 @@ function Actionsheet(
</div>
);
const Option = (item: ActionsheetItem) => (
const Option = (item: ActionsheetItem, index: number) => (
<div
class={[
bem('item', { disabled: item.disabled || item.loading }),
@ -62,7 +62,7 @@ function Actionsheet(
item.callback(item);
}
emit(ctx, 'select', item);
emit(ctx, 'select', item, index);
}
}}
>

View File

@ -33,7 +33,8 @@ test('callback events', () => {
expect(callback.mock.calls.length).toBe(1);
expect(onCancel.mock.calls.length).toBeTruthy();
expect(onInput.mock.calls[0][0]).toBeFalsy();
expect(onSelect.mock.calls[0][0]).toBeTruthy();
expect(onSelect.mock.calls[0][0].name).toEqual('Option');
expect(onSelect.mock.calls[0][1]).toEqual(0);
expect(onSelect.mock.calls[0][1]).toBeFalsy();
expect(wrapper).toMatchSnapshot();
});

View File

@ -95,7 +95,7 @@ export default {
| 事件名 | 说明 | 参数 |
|------|------|------|
| select | 选中选项时触发,禁用或加载状态下不会触发 | item: 选项对应的对象 |
| select | 选中选项时触发,禁用或加载状态下不会触发 | item: 选项对应的对象, index: 选择对应的索引 |
| cancel | 取消按钮点击时触发 | - |
### actions