mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-08-07 13:09:45 +08:00
chore(Cascader): fix some issues (#9756)
This commit is contained in:
parent
94539d8f74
commit
5d85f9ca9e
@ -259,7 +259,7 @@ export default defineComponent({
|
|||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
{slots['options-top']
|
{slots['options-top']
|
||||||
? slots['options-top']({ activeTab: activeTab.value })
|
? slots['options-top']({ tabIndex: activeTab.value })
|
||||||
: null}
|
: null}
|
||||||
{renderOptions(options, selected, tabIndex)}
|
{renderOptions(options, selected, tabIndex)}
|
||||||
</Tab>
|
</Tab>
|
||||||
|
@ -200,16 +200,17 @@ export default {
|
|||||||
### Custom Content
|
### Custom Content
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<van-cascader
|
<van-cascader v-model="code" title="Select Area" :options="options">
|
||||||
v-model="code"
|
<template #options-top="{ tabIndex }">
|
||||||
title="Select Area"
|
<div class="current-level">Current level is {{ tabIndex }}</div>
|
||||||
:options="options"
|
|
||||||
:field-names="fieldNames"
|
|
||||||
>
|
|
||||||
<template #options-top="{ activeTab }">
|
|
||||||
<span>Current level {{activeTab}}</span>
|
|
||||||
</template>
|
</template>
|
||||||
</van-cascader>
|
</van-cascader>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.current-level {
|
||||||
|
padding: 10px 16px 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
@ -218,11 +219,6 @@ import { ref } from 'vue';
|
|||||||
export default {
|
export default {
|
||||||
setup() {
|
setup() {
|
||||||
const code = ref('');
|
const code = ref('');
|
||||||
const fieldNames = {
|
|
||||||
text: 'name',
|
|
||||||
value: 'code',
|
|
||||||
children: 'items',
|
|
||||||
};
|
|
||||||
const options = [
|
const options = [
|
||||||
{
|
{
|
||||||
name: 'Zhejiang',
|
name: 'Zhejiang',
|
||||||
@ -239,7 +235,6 @@ export default {
|
|||||||
return {
|
return {
|
||||||
code,
|
code,
|
||||||
options,
|
options,
|
||||||
fieldNames,
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -287,7 +282,7 @@ export default {
|
|||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| title | Custom title | - |
|
| title | Custom title | - |
|
||||||
| option `v3.1.4` | Custom option text | _{ option: Option, selected: boolean }_ |
|
| option `v3.1.4` | Custom option text | _{ option: Option, selected: boolean }_ |
|
||||||
| options-top | Custom the content above options | - |
|
| options-top `v3.2.7` | Custom the content above options | _{ tabIndex: number }_ |
|
||||||
|
|
||||||
### Types
|
### Types
|
||||||
|
|
||||||
|
@ -210,16 +210,17 @@ export default {
|
|||||||
### 自定义选项上方内容
|
### 自定义选项上方内容
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<van-cascader
|
<van-cascader v-model="code" title="请选择所在地区" :options="options">
|
||||||
v-model="code"
|
<template #options-top="{ tabIndex }">
|
||||||
title="请选择所在地区"
|
<div class="current-level">当前为第 {{ tabIndex }} 级</div>
|
||||||
:options="options"
|
|
||||||
:field-names="fieldNames"
|
|
||||||
>
|
|
||||||
<template #options-top="{ activeTab }">
|
|
||||||
<span>当前为第{{ tabIndex }}级</span>
|
|
||||||
</template>
|
</template>
|
||||||
</van-cascader>
|
</van-cascader>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.current-level {
|
||||||
|
padding: 10px 16px 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
@ -228,11 +229,6 @@ import { ref } from 'vue';
|
|||||||
export default {
|
export default {
|
||||||
setup() {
|
setup() {
|
||||||
const code = ref('');
|
const code = ref('');
|
||||||
const fieldNames = {
|
|
||||||
text: 'name',
|
|
||||||
value: 'code',
|
|
||||||
children: 'items',
|
|
||||||
};
|
|
||||||
const options = [
|
const options = [
|
||||||
{
|
{
|
||||||
name: '浙江省',
|
name: '浙江省',
|
||||||
@ -249,7 +245,6 @@ export default {
|
|||||||
return {
|
return {
|
||||||
code,
|
code,
|
||||||
options,
|
options,
|
||||||
fieldNames,
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -299,7 +294,7 @@ export default {
|
|||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| title | 自定义顶部标题 | - |
|
| title | 自定义顶部标题 | - |
|
||||||
| option `v3.1.4` | 自定义选项文字 | _{ option: Option, selected: boolean }_ |
|
| option `v3.1.4` | 自定义选项文字 | _{ option: Option, selected: boolean }_ |
|
||||||
| options-top | 自定义选项上方的内容 | - |
|
| options-top `v3.2.7` | 自定义选项上方的内容 | _{ tabIndex: number }_ |
|
||||||
|
|
||||||
### 类型定义
|
### 类型定义
|
||||||
|
|
||||||
|
@ -26,8 +26,9 @@ const t = useTranslate({
|
|||||||
{ text: '杭州市', value: '330100' },
|
{ text: '杭州市', value: '330100' },
|
||||||
{ text: '宁波市', value: '330200' },
|
{ text: '宁波市', value: '330200' },
|
||||||
],
|
],
|
||||||
|
currentLevel: (level: number) => `当前为第 ${level} 级`,
|
||||||
|
customContent: '自定义选项上方内容',
|
||||||
customFieldNames: '自定义字段名',
|
customFieldNames: '自定义字段名',
|
||||||
customContent: '自定义内容',
|
|
||||||
},
|
},
|
||||||
'en-US': {
|
'en-US': {
|
||||||
area: 'Area',
|
area: 'Area',
|
||||||
@ -46,8 +47,9 @@ const t = useTranslate({
|
|||||||
{ text: 'Hangzhou', value: '330100' },
|
{ text: 'Hangzhou', value: '330100' },
|
||||||
{ text: 'Ningbo', value: '330200' },
|
{ text: 'Ningbo', value: '330200' },
|
||||||
],
|
],
|
||||||
customFieldNames: 'Custom Field Names',
|
currentLevel: (level: number) => `Current level is ${level}`,
|
||||||
customContent: 'Custom Content',
|
customContent: 'Custom Content',
|
||||||
|
customFieldNames: 'Custom Field Names',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -268,10 +270,16 @@ const onFinish = (
|
|||||||
@close="customContentState.show = false"
|
@close="customContentState.show = false"
|
||||||
@finish="onFinish(customContentState, $event)"
|
@finish="onFinish(customContentState, $event)"
|
||||||
>
|
>
|
||||||
<template #options-top="{ activeTab }">
|
<template #options-top="{ tabIndex }">
|
||||||
<span>当前为第{{ activeTab }}级</span>
|
<div class="current-level">{{ t('currentLevel', tabIndex) }}</div>
|
||||||
</template>
|
</template>
|
||||||
</van-cascader>
|
</van-cascader>
|
||||||
</van-popup>
|
</van-popup>
|
||||||
</demo-block>
|
</demo-block>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<style lang="less">
|
||||||
|
.current-level {
|
||||||
|
padding: 10px 16px 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
@ -93,4 +93,27 @@ exports[`should render demo and match snapshot 1`] = `
|
|||||||
</i>
|
</i>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<div class="van-cell van-cell--clickable van-field"
|
||||||
|
role="button"
|
||||||
|
tabindex="0"
|
||||||
|
>
|
||||||
|
<div class="van-cell__title van-field__label">
|
||||||
|
<label>
|
||||||
|
Area
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="van-cell__value van-field__value">
|
||||||
|
<div class="van-field__body">
|
||||||
|
<input type="text"
|
||||||
|
class="van-field__control"
|
||||||
|
readonly
|
||||||
|
placeholder="Select Area"
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<i class="van-badge__wrapper van-icon van-icon-arrow van-cell__right-icon">
|
||||||
|
</i>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
`;
|
`;
|
||||||
|
@ -1,5 +1,25 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[` should allow more custom content 1`] = `
|
||||||
|
<div class="van-tab__pane">
|
||||||
|
tab index: 1
|
||||||
|
<ul class="van-cascader__options">
|
||||||
|
<li class="van-cascader__option van-cascader__option--selected">
|
||||||
|
<span>
|
||||||
|
Zhejiang
|
||||||
|
</span>
|
||||||
|
<i class="van-badge__wrapper van-icon van-icon-success van-cascader__selected-icon">
|
||||||
|
</i>
|
||||||
|
</li>
|
||||||
|
<li class="van-cascader__option">
|
||||||
|
<span>
|
||||||
|
Jiangsu
|
||||||
|
</span>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`should change close icon when using close-icon prop 1`] = `
|
exports[`should change close icon when using close-icon prop 1`] = `
|
||||||
<i class="van-badge__wrapper van-icon van-icon-success van-cascader__close-icon">
|
<i class="van-badge__wrapper van-icon van-icon-success van-cascader__close-icon">
|
||||||
</i>
|
</i>
|
||||||
|
@ -245,19 +245,18 @@ test('should allow to custom the color of option', async () => {
|
|||||||
test(' should allow more custom content', async () => {
|
test(' should allow more custom content', async () => {
|
||||||
const wrapper = mount(Cascader, {
|
const wrapper = mount(Cascader, {
|
||||||
slots: {
|
slots: {
|
||||||
'options-top': ({ activeTab }) => activeTab,
|
'options-top': ({ tabIndex }) => `tab index: ${tabIndex}`,
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
options,
|
options,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
await later();
|
await later();
|
||||||
wrapper
|
await wrapper
|
||||||
.findAll('.van-cascader__options')[0]
|
.findAll('.van-cascader__options')[0]
|
||||||
.find('.van-cascader__option')
|
.find('.van-cascader__option')
|
||||||
.trigger('click');
|
.trigger('click');
|
||||||
wrapper.vm.$nextTick(() => {
|
|
||||||
const top = wrapper.find('.van-tab__pane');
|
expect(wrapper.find('.van-tab__pane').html()).toMatchSnapshot();
|
||||||
expect(top.text()).toBe('1');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
@ -6,7 +6,7 @@ import locale from '../locale';
|
|||||||
export function createTranslate(name: string) {
|
export function createTranslate(name: string) {
|
||||||
const prefix = camelize(name) + '.';
|
const prefix = camelize(name) + '.';
|
||||||
|
|
||||||
return (path: string, ...args: unknown[]): string => {
|
return (path: string, ...args: unknown[]) => {
|
||||||
const messages = locale.messages();
|
const messages = locale.messages();
|
||||||
const message = get(messages, prefix + path) || get(messages, path);
|
const message = get(messages, prefix + path) || get(messages, path);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user