feat(Picker): expose option index to option slot (#11594)

This commit is contained in:
neverland 2023-02-18 15:54:35 +08:00 committed by GitHub
parent 5b9d870bf8
commit 012d2aa141
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 63 additions and 58 deletions

View File

@ -194,15 +194,15 @@ export default {
### Slots
| Name | Description | SlotProps |
| -------------- | ---------------------------- | ---------------------- |
| toolbar | Custom toolbar content | - |
| title | Custom title | - |
| confirm | Custom confirm button text | - |
| cancel | Custom cancel button text | - |
| option | Custom option content | _option: PickerOption_ |
| columns-top | Custom content above columns | - |
| columns-bottom | Custom content below columns | - |
| Name | Description | SlotProps |
| --- | --- | --- |
| toolbar | Custom toolbar content | - |
| title | Custom title | - |
| confirm | Custom confirm button text | - |
| cancel | Custom cancel button text | - |
| option | Custom option content | _option: PickerOption, index: number_ |
| columns-top | Custom content above columns | - |
| columns-bottom | Custom content below columns | - |
### Types

View File

@ -200,15 +200,15 @@ export default {
### Slots
| 名称 | 说明 | 参数 |
| -------------- | ---------------------- | ---------------------- |
| toolbar | 自定义整个顶部栏的内容 | - |
| title | 自定义标题内容 | - |
| confirm | 自定义确认按钮内容 | - |
| cancel | 自定义取消按钮内容 | - |
| option | 自定义选项内容 | _option: PickerOption_ |
| columns-top | 自定义选项上方内容 | - |
| columns-bottom | 自定义选项下方内容 | - |
| 名称 | 说明 | 参数 |
| --- | --- | --- |
| toolbar | 自定义整个顶部栏的内容 | - |
| title | 自定义标题内容 | - |
| confirm | 自定义确认按钮内容 | - |
| cancel | 自定义取消按钮内容 | - |
| option | 自定义选项内容 | _option: PickerOption, index: number_ |
| columns-top | 自定义选项上方内容 | - |
| columns-bottom | 自定义选项下方内容 | - |
### 类型定义

View File

@ -235,7 +235,11 @@ export default defineComponent({
return (
<li {...data}>
{slots.option ? slots.option(option) : <div {...childData} />}
{slots.option ? (
slots.option(option, index)
) : (
<div {...childData} />
)}
</li>
);
});

View File

@ -362,15 +362,15 @@ export default {
### Slots
| Name | Description | SlotProps |
| --------------- | ---------------------------- | ---------------------- |
| toolbar `3.1.2` | Custom toolbar content | - |
| title | Custom title | - |
| confirm | Custom confirm button text | - |
| cancel | Custom cancel button text | - |
| option | Custom option content | _option: PickerOption_ |
| columns-top | Custom content above columns | - |
| columns-bottom | Custom content below columns | - |
| Name | Description | SlotProps |
| --- | --- | --- |
| toolbar `3.1.2` | Custom toolbar content | - |
| title | Custom title | - |
| confirm | Custom confirm button text | - |
| cancel | Custom cancel button text | - |
| option | Custom option content | _option: PickerOption, index: number_ |
| columns-top | Custom content above columns | - |
| columns-bottom | Custom content below columns | - |
### Data Structure of PickerOption

View File

@ -383,15 +383,15 @@ export default {
### Slots
| 名称 | 说明 | 参数 |
| ---------------- | ---------------------- | ---------------------- |
| toolbar `v3.1.2` | 自定义整个顶部栏的内容 | - |
| title | 自定义标题内容 | - |
| confirm | 自定义确认按钮内容 | - |
| cancel | 自定义取消按钮内容 | - |
| option | 自定义选项内容 | _option: PickerOption_ |
| columns-top | 自定义选项上方内容 | - |
| columns-bottom | 自定义选项下方内容 | - |
| 名称 | 说明 | 参数 |
| --- | --- | --- |
| toolbar `v3.1.2` | 自定义整个顶部栏的内容 | - |
| title | 自定义标题内容 | - |
| confirm | 自定义确认按钮内容 | - |
| cancel | 自定义取消按钮内容 | - |
| option | 自定义选项内容 | _option: PickerOption, index: number_ |
| columns-top | 自定义选项上方内容 | - |
| columns-bottom | 自定义选项下方内容 | - |
### PickerOption 数据结构

View File

@ -82,14 +82,14 @@ exports[`should render option slot correctly 1`] = `
tabindex="0"
class="van-picker-column__item van-picker-column__item--selected"
>
Custom 1990
Custom 1990, index: 0
</li>
<li role="button"
style="height: 44px;"
tabindex="0"
class="van-picker-column__item"
>
Custom 1991
Custom 1991, index: 1
</li>
</ul>
</div>

View File

@ -42,7 +42,8 @@ test('should render option slot correctly', () => {
columns: simpleColumn,
},
slots: {
option: (option: PickerOption) => `Custom ${option.text}`,
option: (option: PickerOption, index) =>
`Custom ${option.text}, index: ${index}`,
},
});

View File

@ -195,15 +195,15 @@ export default {
### Slots
| Name | Description | SlotProps |
| -------------- | ---------------------------- | ---------------------- |
| toolbar | Custom toolbar content | - |
| title | Custom title | - |
| confirm | Custom confirm button text | - |
| cancel | Custom cancel button text | - |
| option | Custom option content | _option: PickerOption_ |
| columns-top | Custom content above columns | - |
| columns-bottom | Custom content below columns | - |
| Name | Description | SlotProps |
| --- | --- | --- |
| toolbar | Custom toolbar content | - |
| title | Custom title | - |
| confirm | Custom confirm button text | - |
| cancel | Custom cancel button text | - |
| option | Custom option content | _option: PickerOption, index: number_ |
| columns-top | Custom content above columns | - |
| columns-bottom | Custom content below columns | - |
### Types

View File

@ -196,15 +196,15 @@ export default {
### Slots
| 名称 | 说明 | 参数 |
| -------------- | ---------------------- | ---------------------- |
| toolbar | 自定义整个顶部栏的内容 | - |
| title | 自定义标题内容 | - |
| confirm | 自定义确认按钮内容 | - |
| cancel | 自定义取消按钮内容 | - |
| option | 自定义选项内容 | _option: PickerOption_ |
| columns-top | 自定义选项上方内容 | - |
| columns-bottom | 自定义选项下方内容 | - |
| 名称 | 说明 | 参数 |
| --- | --- | --- |
| toolbar | 自定义整个顶部栏的内容 | - |
| title | 自定义标题内容 | - |
| confirm | 自定义确认按钮内容 | - |
| cancel | 自定义取消按钮内容 | - |
| option | 自定义选项内容 | _option: PickerOption, index: number_ |
| columns-top | 自定义选项上方内容 | - |
| columns-bottom | 自定义选项下方内容 | - |
### 类型定义