From b3ca94dfadd446a03cb9785f80f5eda1443abfb8 Mon Sep 17 00:00:00 2001 From: neverland Date: Fri, 2 Jul 2021 16:53:11 +0800 Subject: [PATCH] chore: add warn of deprecated slot (#8972) * chore: migrate cell default slot * chore: add warn of deprecated slot --- src/cell/Cell.tsx | 10 +++++++++- src/cell/test/__snapshots__/index.spec.ts.snap | 8 -------- src/cell/test/index.spec.ts | 9 --------- src/picker/Picker.tsx | 6 ++++++ 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/cell/Cell.tsx b/src/cell/Cell.tsx index 938f10f77..12a05be67 100644 --- a/src/cell/Cell.tsx +++ b/src/cell/Cell.tsx @@ -33,7 +33,7 @@ export const cellProps = { valueClass: unknownProp, labelClass: unknownProp, titleClass: unknownProp, - titleStyle: null as unknown as PropType, + titleStyle: (null as unknown) as PropType, arrowDirection: String as PropType, clickable: { type: Boolean as PropType, @@ -47,6 +47,14 @@ export default defineComponent({ props: extend({}, cellProps, routeProps), setup(props, { slots }) { + if (process.env.NODE_ENV !== 'production') { + if (slots.default) { + console.warn( + '[Vant] Cell: "default" slot is deprecated, please use "value" slot instead.' + ); + } + } + const route = useRoute(); const renderLabel = () => { diff --git a/src/cell/test/__snapshots__/index.spec.ts.snap b/src/cell/test/__snapshots__/index.spec.ts.snap index 4fa0247e7..9c5f1ed3a 100644 --- a/src/cell/test/__snapshots__/index.spec.ts.snap +++ b/src/cell/test/__snapshots__/index.spec.ts.snap @@ -12,14 +12,6 @@ exports[`should change icon class prefix when using icon-prefix prop 1`] = ` `; -exports[`should render default slot correctly 1`] = ` -
-
- Custom Value -
-
-`; - exports[`should render extra slot correctly 1`] = `
Custom Extra diff --git a/src/cell/test/index.spec.ts b/src/cell/test/index.spec.ts index 46a9fadec..ecff12cdc 100644 --- a/src/cell/test/index.spec.ts +++ b/src/cell/test/index.spec.ts @@ -1,15 +1,6 @@ import { Cell } from '..'; import { mount } from '../../../test'; -test('should render default slot correctly', () => { - const wrapper = mount(Cell, { - slots: { - default: () => 'Custom Value', - }, - }); - expect(wrapper.html()).toMatchSnapshot(); -}); - test('should render value slot correctly', () => { const wrapper = mount(Cell, { slots: { diff --git a/src/picker/Picker.tsx b/src/picker/Picker.tsx index 9fe0c6473..947f54640 100644 --- a/src/picker/Picker.tsx +++ b/src/picker/Picker.tsx @@ -92,6 +92,12 @@ export default defineComponent({ emits: ['confirm', 'cancel', 'change'], setup(props, { emit, slots }) { + if (slots.default) { + console.warn( + '[Vant] Picker: "default" slot is deprecated, please use "toolbar" slot instead.' + ); + } + const formattedColumns = ref([]); const { text: textKey, values: valuesKey, children: childrenKey } = extend(