Merge branch 'dev' into next
This commit is contained in:
@@ -42,7 +42,6 @@
|
||||
"@types/fs-extra": "^9.0.13",
|
||||
"@types/less": "^3.0.3",
|
||||
"@types/markdown-it": "^12.2.3",
|
||||
"@types/react": "^18",
|
||||
"@jest/types": "^27",
|
||||
"vue": "^3.2.27",
|
||||
"react": "^18",
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
import { defineComponent, type ExtractPropTypes } from 'vue';
|
||||
import { defineComponent, ref, type ExtractPropTypes } from 'vue';
|
||||
import { truthProp, createNamespace } from '../utils';
|
||||
import { useChildren } from '@vant/use';
|
||||
import { usePlaceholder } from '../composables/use-placeholder';
|
||||
|
||||
const [name, bem] = createNamespace('action-bar');
|
||||
|
||||
export const ACTION_BAR_KEY = Symbol(name);
|
||||
|
||||
const actionBarProps = {
|
||||
placeholder: Boolean,
|
||||
safeAreaInsetBottom: truthProp,
|
||||
};
|
||||
|
||||
@@ -18,16 +20,26 @@ export default defineComponent({
|
||||
props: actionBarProps,
|
||||
|
||||
setup(props, { slots }) {
|
||||
const root = ref<HTMLElement>();
|
||||
const renderPlaceholder = usePlaceholder(root, bem);
|
||||
const { linkChildren } = useChildren(ACTION_BAR_KEY);
|
||||
|
||||
linkChildren();
|
||||
|
||||
return () => (
|
||||
const renderActionBar = () => (
|
||||
<div
|
||||
ref={root}
|
||||
class={[bem(), { 'van-safe-area-bottom': props.safeAreaInsetBottom }]}
|
||||
>
|
||||
{slots.default?.()}
|
||||
</div>
|
||||
);
|
||||
|
||||
return () => {
|
||||
if (props.placeholder) {
|
||||
return renderPlaceholder(renderActionBar);
|
||||
}
|
||||
return renderActionBar();
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
@@ -90,6 +90,7 @@ Use `badge` prop to show badge in icon.
|
||||
| Attribute | Description | Type | Default |
|
||||
| --- | --- | --- | --- |
|
||||
| safe-area-inset-bottom | Whether to enable bottom safe area adaptation | _boolean_ | `true` |
|
||||
| placeholder `v3.5.1` | Whether to generate a placeholder element | _boolean_ | `false` |
|
||||
|
||||
### ActionBarIcon Props
|
||||
|
||||
|
||||
@@ -94,6 +94,7 @@ export default {
|
||||
| 参数 | 说明 | 类型 | 默认值 |
|
||||
| --- | --- | --- | --- |
|
||||
| safe-area-inset-bottom | 是否开启[底部安全区适配](#/zh-CN/advanced-usage#di-bu-an-quan-qu-gua-pei) | _boolean_ | `true` |
|
||||
| placeholder `v3.5.1` | 是否在标签位置生成一个等高的占位元素 | _boolean_ | `false` |
|
||||
|
||||
### ActionBarIcon Props
|
||||
|
||||
|
||||
@@ -4,3 +4,12 @@ exports[`should allow to disable safe-area-inset-bottom prop 1`] = `
|
||||
<div class="van-action-bar">
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`should render placeholder element when using placeholder prop 1`] = `
|
||||
<div class="van-action-bar__placeholder"
|
||||
style="height: 50px;"
|
||||
>
|
||||
<div class="van-action-bar van-safe-area-bottom">
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ActionBar } from '..';
|
||||
import { mount } from '../../../test';
|
||||
import { later, mockGetBoundingClientRect, mount } from '../../../test';
|
||||
|
||||
test('should allow to disable safe-area-inset-bottom prop', () => {
|
||||
const wrapper = mount(ActionBar, {
|
||||
@@ -10,3 +10,16 @@ test('should allow to disable safe-area-inset-bottom prop', () => {
|
||||
|
||||
expect(wrapper.html()).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('should render placeholder element when using placeholder prop', async () => {
|
||||
const restore = mockGetBoundingClientRect({ height: 50 });
|
||||
const wrapper = mount(ActionBar, {
|
||||
props: {
|
||||
placeholder: true,
|
||||
},
|
||||
});
|
||||
|
||||
await later();
|
||||
expect(wrapper.html()).toMatchSnapshot();
|
||||
restore();
|
||||
});
|
||||
|
||||
@@ -185,6 +185,10 @@ export default defineComponent({
|
||||
const months: Date[] = [];
|
||||
const cursor = new Date(props.minDate);
|
||||
|
||||
if (props.lazyRender && !props.show && props.poppable) {
|
||||
return months;
|
||||
}
|
||||
|
||||
cursor.setDate(1);
|
||||
|
||||
do {
|
||||
|
||||
@@ -128,6 +128,8 @@ export default defineComponent({
|
||||
'clear',
|
||||
'keypress',
|
||||
'clickInput',
|
||||
'endValidate',
|
||||
'startValidate',
|
||||
'clickLeftIcon',
|
||||
'clickRightIcon',
|
||||
'update:modelValue',
|
||||
@@ -218,19 +220,24 @@ export default defineComponent({
|
||||
state.validateMessage = '';
|
||||
};
|
||||
|
||||
const endValidate = () => emit('endValidate', { status: state.status });
|
||||
|
||||
const validate = (rules = props.rules) =>
|
||||
new Promise<FieldValidateError | void>((resolve) => {
|
||||
resetValidation();
|
||||
if (rules) {
|
||||
emit('startValidate');
|
||||
runRules(rules).then(() => {
|
||||
if (state.status === 'failed') {
|
||||
resolve({
|
||||
name: props.name,
|
||||
message: state.validateMessage,
|
||||
});
|
||||
endValidate();
|
||||
} else {
|
||||
state.status = 'passed';
|
||||
resolve();
|
||||
endValidate();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
||||
@@ -298,6 +298,8 @@ Use `input-align` prop to align the input value.
|
||||
| click-input | Emitted when the input is clicked | _event: MouseEvent_ |
|
||||
| click-left-icon | Emitted when the left icon is clicked | _event: MouseEvent_ |
|
||||
| click-right-icon | Emitted when the right icon is clicked | _event: MouseEvent_ |
|
||||
| start-validate `v3.5.1` | Emitted when start validation | - |
|
||||
| end-validate `v3.5.1` | Emitted when end validation | _{ status: string }_ |
|
||||
|
||||
### Methods
|
||||
|
||||
|
||||
@@ -307,16 +307,18 @@ export default {
|
||||
|
||||
### Events
|
||||
|
||||
| 事件 | 说明 | 回调参数 |
|
||||
| ------------------ | -------------------- | ------------------------------ |
|
||||
| 事件 | 说明 | 回调参数 |
|
||||
| --- | --- | --- |
|
||||
| update:model-value | 输入框内容变化时触发 | _value: string (当前输入的值)_ |
|
||||
| focus | 输入框获得焦点时触发 | _event: Event_ |
|
||||
| blur | 输入框失去焦点时触发 | _event: Event_ |
|
||||
| clear | 点击清除按钮时触发 | _event: MouseEvent_ |
|
||||
| click | 点击组件时触发 | _event: MouseEvent_ |
|
||||
| click-input | 点击输入区域时触发 | _event: MouseEvent_ |
|
||||
| click-left-icon | 点击左侧图标时触发 | _event: MouseEvent_ |
|
||||
| click-right-icon | 点击右侧图标时触发 | _event: MouseEvent_ |
|
||||
| focus | 输入框获得焦点时触发 | _event: Event_ |
|
||||
| blur | 输入框失去焦点时触发 | _event: Event_ |
|
||||
| clear | 点击清除按钮时触发 | _event: MouseEvent_ |
|
||||
| click | 点击组件时触发 | _event: MouseEvent_ |
|
||||
| click-input | 点击输入区域时触发 | _event: MouseEvent_ |
|
||||
| click-left-icon | 点击左侧图标时触发 | _event: MouseEvent_ |
|
||||
| click-right-icon | 点击右侧图标时触发 | _event: MouseEvent_ |
|
||||
| start-validate `v3.5.1` | 开始表单校验时触发 | - |
|
||||
| end-validate `v3.5.1` | 结束表单校验时触发 | _{ status: string }_ |
|
||||
|
||||
### 方法
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { mount } from '../../../test';
|
||||
import { later, mount } from '../../../test';
|
||||
import { submitForm, mountSimpleRulesForm } from './shared';
|
||||
import { Form } from '..';
|
||||
import { Field } from '../../field';
|
||||
@@ -64,3 +64,55 @@ test('should emit failed event correctly when rule message is empty', async () =
|
||||
values: { A: '' },
|
||||
});
|
||||
});
|
||||
|
||||
test('Field should emit startValidate event when validation start', async () => {
|
||||
const onStart = jest.fn();
|
||||
const wrapper = mount({
|
||||
render() {
|
||||
return (
|
||||
<Form>
|
||||
<Field
|
||||
name="A"
|
||||
rules={[{ required: true }]}
|
||||
modelValue="bar"
|
||||
onStartValidate={onStart}
|
||||
/>
|
||||
</Form>
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
await submitForm(wrapper);
|
||||
expect(onStart).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test('Field should emit endValidate event when validation end', async () => {
|
||||
const onEnd = jest.fn();
|
||||
const rules = [
|
||||
{
|
||||
validator: () =>
|
||||
new Promise<boolean>((resolve) => {
|
||||
setTimeout(() => resolve(true), 10);
|
||||
}),
|
||||
},
|
||||
];
|
||||
const wrapper = mount({
|
||||
render() {
|
||||
return (
|
||||
<Form>
|
||||
<Field
|
||||
name="A"
|
||||
rules={rules}
|
||||
modelValue="bar"
|
||||
onEndValidate={onEnd}
|
||||
/>
|
||||
</Form>
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
await submitForm(wrapper);
|
||||
expect(onEnd).toHaveBeenCalledTimes(0);
|
||||
await later(50);
|
||||
expect(onEnd).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
@@ -264,7 +264,8 @@ export default defineComponent({
|
||||
});
|
||||
|
||||
onDeactivated(() => {
|
||||
if (props.show) {
|
||||
// teleported popup should be closed when deactivated
|
||||
if (props.show && props.teleport) {
|
||||
close();
|
||||
shouldReopen = true;
|
||||
}
|
||||
|
||||
@@ -106,6 +106,7 @@ export default {
|
||||
| disabled | Whether to disable button | _boolean_ | `false` |
|
||||
| loading | Whether to show loading icon | _boolean_ | `false` |
|
||||
| safe-area-inset-bottom | Whether to enable bottom safe area adaptation | _boolean_ | `true` |
|
||||
| placeholder `v3.5.1` | Whether to generate a placeholder element | _boolean_ | `false` |
|
||||
|
||||
### Events
|
||||
|
||||
|
||||
@@ -113,6 +113,7 @@ export default {
|
||||
| disabled | 是否禁用按钮 | _boolean_ | `false` |
|
||||
| loading | 是否显示将按钮显示为加载中状态 | _boolean_ | `false` |
|
||||
| safe-area-inset-bottom | 是否开启[底部安全区适配](#/zh-CN/advanced-usage#di-bu-an-quan-qu-gua-pei) | _boolean_ | `true` |
|
||||
| placeholder `v3.5.1` | 是否在标签位置生成一个等高的占位元素 | _boolean_ | `false` |
|
||||
|
||||
### Events
|
||||
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import { defineComponent, type PropType, type ExtractPropTypes } from 'vue';
|
||||
import {
|
||||
ref,
|
||||
defineComponent,
|
||||
type PropType,
|
||||
type ExtractPropTypes,
|
||||
} from 'vue';
|
||||
import {
|
||||
truthProp,
|
||||
makeStringProp,
|
||||
@@ -9,6 +14,7 @@ import {
|
||||
// Components
|
||||
import { Icon } from '../icon';
|
||||
import { Button, ButtonType } from '../button';
|
||||
import { usePlaceholder } from '../composables/use-placeholder';
|
||||
|
||||
const [name, bem, t] = createNamespace('submit-bar');
|
||||
|
||||
@@ -27,6 +33,7 @@ const submitBarProps = {
|
||||
buttonType: makeStringProp<ButtonType>('danger'),
|
||||
buttonColor: String,
|
||||
suffixLabel: String,
|
||||
placeholder: Boolean,
|
||||
decimalLength: makeNumericProp(2),
|
||||
safeAreaInsetBottom: truthProp,
|
||||
};
|
||||
@@ -41,6 +48,9 @@ export default defineComponent({
|
||||
emits: ['submit'],
|
||||
|
||||
setup(props, { emit, slots }) {
|
||||
const root = ref<HTMLElement>();
|
||||
const renderPlaceholder = usePlaceholder(root, bem);
|
||||
|
||||
const renderText = () => {
|
||||
const { price, label, currency, textAlign, suffixLabel, decimalLength } =
|
||||
props;
|
||||
@@ -99,8 +109,9 @@ export default defineComponent({
|
||||
);
|
||||
};
|
||||
|
||||
return () => (
|
||||
const renderSubmitBar = () => (
|
||||
<div
|
||||
ref={root}
|
||||
class={[bem(), { 'van-safe-area-bottom': props.safeAreaInsetBottom }]}
|
||||
>
|
||||
{slots.top?.()}
|
||||
@@ -112,5 +123,12 @@ export default defineComponent({
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
return () => {
|
||||
if (props.placeholder) {
|
||||
return renderPlaceholder(renderSubmitBar);
|
||||
}
|
||||
return renderSubmitBar();
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
@@ -47,6 +47,23 @@ exports[`should render disabled submit button correctly 1`] = `
|
||||
</button>
|
||||
`;
|
||||
|
||||
exports[`should render placeholder element when using placeholder prop 1`] = `
|
||||
<div class="van-submit-bar__placeholder"
|
||||
style="height: 50px;"
|
||||
>
|
||||
<div class="van-submit-bar van-safe-area-bottom">
|
||||
<div class="van-submit-bar__bar">
|
||||
<button type="button"
|
||||
class="van-button van-button--danger van-button--normal van-button--round van-submit-bar__button van-submit-bar__button--danger"
|
||||
>
|
||||
<div class="van-button__content">
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`should render suffix-label correctly 1`] = `
|
||||
<div class="van-submit-bar__text">
|
||||
<span>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { SubmitBar } from '..';
|
||||
import { mount } from '../../../test';
|
||||
import { later, mockGetBoundingClientRect, mount } from '../../../test';
|
||||
|
||||
test('should emit submit event when submit button is clicked', () => {
|
||||
const wrapper = mount(SubmitBar);
|
||||
@@ -107,3 +107,16 @@ test('should render button slot correctly', () => {
|
||||
});
|
||||
expect(wrapper.html()).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('should render placeholder element when using placeholder prop', async () => {
|
||||
const restore = mockGetBoundingClientRect({ height: 50 });
|
||||
const wrapper = mount(SubmitBar, {
|
||||
props: {
|
||||
placeholder: true,
|
||||
},
|
||||
});
|
||||
|
||||
await later();
|
||||
expect(wrapper.html()).toMatchSnapshot();
|
||||
restore();
|
||||
});
|
||||
|
||||
@@ -65,9 +65,11 @@ Using `node` slot to custom the content of the node.
|
||||
|
||||
```html
|
||||
<van-switch v-model="checked">
|
||||
<div class="icon-wrapper">
|
||||
<van-icon :name="checked ? 'success' : 'cross'" />
|
||||
</div>
|
||||
<template #node>
|
||||
<div class="icon-wrapper">
|
||||
<van-icon :name="checked ? 'success' : 'cross'" />
|
||||
</div>
|
||||
</template>
|
||||
</van-switch>
|
||||
|
||||
<style>
|
||||
|
||||
@@ -75,9 +75,11 @@ export default {
|
||||
|
||||
```html
|
||||
<van-switch v-model="checked">
|
||||
<div class="icon-wrapper">
|
||||
<van-icon :name="checked ? 'success' : 'cross'" />
|
||||
</div>
|
||||
<template #node>
|
||||
<div class="icon-wrapper">
|
||||
<van-icon :name="checked ? 'success' : 'cross'" />
|
||||
</div>
|
||||
</template>
|
||||
</van-switch>
|
||||
|
||||
<style>
|
||||
|
||||
Reference in New Issue
Block a user