mirror of
				https://gitee.com/vant-contrib/vant.git
				synced 2025-10-27 01:32:10 +08:00 
			
		
		
		
	[improvement] Actionsheet: add index param for select event (#2917)
This commit is contained in:
		
							parent
							
								
									c9e578c0cf
								
							
						
					
					
						commit
						bfa8f38585
					
				| @ -90,7 +90,7 @@ Actionsheet will get another style if there is a `title` prop. | |||||||
| 
 | 
 | ||||||
| | Event | Description | Arguments | | | Event | Description | Arguments | | ||||||
| |------|------|------| | |------|------|------| | ||||||
| | select | Triggered when click option | item | | | select | Triggered when click option | item, index | | ||||||
| | cancel | Triggered when cancel click | - | | | cancel | Triggered when cancel click | - | | ||||||
| 
 | 
 | ||||||
| ### Data struct of actions | ### Data struct of actions | ||||||
|  | |||||||
| @ -47,7 +47,7 @@ function Actionsheet( | |||||||
|     </div> |     </div> | ||||||
|   ); |   ); | ||||||
| 
 | 
 | ||||||
|   const Option = (item: ActionsheetItem) => ( |   const Option = (item: ActionsheetItem, index: number) => ( | ||||||
|     <div |     <div | ||||||
|       class={[ |       class={[ | ||||||
|         bem('item', { disabled: item.disabled || item.loading }), |         bem('item', { disabled: item.disabled || item.loading }), | ||||||
| @ -62,7 +62,7 @@ function Actionsheet( | |||||||
|             item.callback(item); |             item.callback(item); | ||||||
|           } |           } | ||||||
| 
 | 
 | ||||||
|           emit(ctx, 'select', item); |           emit(ctx, 'select', item, index); | ||||||
|         } |         } | ||||||
|       }} |       }} | ||||||
|     > |     > | ||||||
|  | |||||||
| @ -33,7 +33,8 @@ test('callback events', () => { | |||||||
|   expect(callback.mock.calls.length).toBe(1); |   expect(callback.mock.calls.length).toBe(1); | ||||||
|   expect(onCancel.mock.calls.length).toBeTruthy(); |   expect(onCancel.mock.calls.length).toBeTruthy(); | ||||||
|   expect(onInput.mock.calls[0][0]).toBeFalsy(); |   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(onSelect.mock.calls[0][1]).toBeFalsy(); | ||||||
|   expect(wrapper).toMatchSnapshot(); |   expect(wrapper).toMatchSnapshot(); | ||||||
| }); | }); | ||||||
|  | |||||||
| @ -95,7 +95,7 @@ export default { | |||||||
| 
 | 
 | ||||||
| | 事件名 | 说明 | 参数 | | | 事件名 | 说明 | 参数 | | ||||||
| |------|------|------| | |------|------|------| | ||||||
| | select | 选中选项时触发,禁用或加载状态下不会触发 | item: 选项对应的对象 | | | select | 选中选项时触发,禁用或加载状态下不会触发 | item: 选项对应的对象, index: 选择对应的索引 | | ||||||
| | cancel | 取消按钮点击时触发 | - | | | cancel | 取消按钮点击时触发 | - | | ||||||
| 
 | 
 | ||||||
| ### actions | ### actions | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user