Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(area): columns-placeholder prop rendering error #12857

Merged
merged 4 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/vant/src/area/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export default {
<van-area
title="Title"
:area-list="areaList"
:columns-placeholder="['Choose', 'Choose', 'Choose']"
:columns-placeholder="['Province', 'City', 'County']"
/>
```

Expand Down
2 changes: 1 addition & 1 deletion packages/vant/src/area/README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export default {
<van-area
title="标题"
:area-list="areaList"
:columns-placeholder="['请选择', '请选择', '请选择']"
:columns-placeholder="['省份', '城市', '区县']"
/>
```

Expand Down
4 changes: 2 additions & 2 deletions packages/vant/src/area/demo/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ const t = useTranslate({
title2: '控制选中项',
title3: '配置显示列',
title4: '配置列占位提示文字',
columnsPlaceholder: ['请选择', '请选择', '请选择'],
columnsPlaceholder: ['省份', '城市', '区县'],
areaList,
},
'en-US': {
title2: 'Model Value',
title3: 'Columns Number',
title4: 'Columns Placeholder',
columnsPlaceholder: ['Choose', 'Choose', 'Choose'],
columnsPlaceholder: ['Province', 'City', 'County'],
areaList: areaListEn,
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ exports[`should render demo and match snapshot 1`] = `
class="van-picker-column__item van-picker-column__item--selected"
>
<div class="van-ellipsis">
Choose
Province
</div>
</li>
<li
Expand Down Expand Up @@ -583,7 +583,7 @@ exports[`should render demo and match snapshot 1`] = `
class="van-picker-column__item van-picker-column__item--selected"
>
<div class="van-ellipsis">
Choose
City
</div>
</li>
</ul>
Expand All @@ -601,7 +601,7 @@ exports[`should render demo and match snapshot 1`] = `
class="van-picker-column__item van-picker-column__item--selected"
>
<div class="van-ellipsis">
Choose
County
</div>
</li>
</ul>
Expand Down
6 changes: 3 additions & 3 deletions packages/vant/src/area/test/__snapshots__/demo.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ exports[`should render demo and match snapshot 1`] = `
class="van-picker-column__item van-picker-column__item--selected"
>
<div class="van-ellipsis">
Choose
Province
</div>
</li>
<li
Expand Down Expand Up @@ -557,7 +557,7 @@ exports[`should render demo and match snapshot 1`] = `
class="van-picker-column__item van-picker-column__item--selected"
>
<div class="van-ellipsis">
Choose
City
</div>
</li>
</ul>
Expand All @@ -574,7 +574,7 @@ exports[`should render demo and match snapshot 1`] = `
class="van-picker-column__item van-picker-column__item--selected"
>
<div class="van-ellipsis">
Choose
County
</div>
</li>
</ul>
Expand Down
18 changes: 18 additions & 0 deletions packages/vant/src/area/test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@ import {
PickerConfirmEventParams,
} from '../../picker';

test('should columns placeholder displayed normally', async () => {
const columnsPlaceholder = ['Province', 'City', 'County'];

const wrapper = mount(Area, {
props: {
areaList,
columnsPlaceholder,
},
});

const columns = await wrapper.findAll('.van-picker-column');
await columns[0].findAll('li')?.[1].trigger('click');
expect(columns[1].find('li').text()).toBe(columnsPlaceholder[1]);

await columns[1].findAll('li')?.[1].trigger('click');
expect(columns[2].find('li').text()).toBe(columnsPlaceholder[2]);
});

test('should emit confirm event after click the confirm button', async () => {
const wrapper = mount(Area, {
props: {
Expand Down
6 changes: 3 additions & 3 deletions packages/vant/src/area/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ export function formatDataForCascade({

const getProvinceChildren = () => {
if (showCity) {
return placeholder.length
return placeholder.length > 1
? [
makeOption(
placeholder[0],
placeholder[1],
AREA_EMPTY_CODE,
showCounty ? [] : undefined,
),
Expand All @@ -71,7 +71,7 @@ export function formatDataForCascade({
if (showCity) {
const getCityChildren = () => {
if (showCounty) {
return placeholder.length ? [makeOption(placeholder[1])] : [];
return placeholder.length > 2 ? [makeOption(placeholder[2])] : [];
}
};

Expand Down
Loading