mirror of
https://gitee.com/vant-contrib/vant.git
synced 2026-07-15 01:51:06 +08:00
Compare commits
4 Commits
8eac20b9cb
...
c669138d60
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c669138d60 | ||
|
|
7b6a99da2f | ||
|
|
bd7ee34eba | ||
|
|
0477c0e2e6 |
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "vant",
|
||||
"version": "4.6.8",
|
||||
"version": "4.7.0",
|
||||
"description": "Mobile UI Components built on Vue",
|
||||
"main": "lib/vant.cjs.js",
|
||||
"module": "es/index.mjs",
|
||||
|
||||
@ -46,10 +46,12 @@ function initInstance() {
|
||||
({ instance } = mountComponent(Wrapper));
|
||||
}
|
||||
|
||||
export function showDialog(options: DialogOptions) {
|
||||
export function showDialog(
|
||||
options: DialogOptions,
|
||||
): Promise<DialogAction | undefined> {
|
||||
/* istanbul ignore if */
|
||||
if (!inBrowser) {
|
||||
return Promise.resolve();
|
||||
return Promise.resolve(undefined);
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
@ -59,7 +61,7 @@ export function showDialog(options: DialogOptions) {
|
||||
|
||||
instance.open(
|
||||
extend({}, currentOptions, options, {
|
||||
callback: (action: DialogAction) => {
|
||||
callback: (action?: DialogAction) => {
|
||||
(action === 'confirm' ? resolve : reject)(action);
|
||||
},
|
||||
}),
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
||||
|
||||
exports[`should allow to render JSX message 1`] = `
|
||||
<div class="van-dialog__message">
|
||||
<div>
|
||||
foo
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
@ -6,20 +6,25 @@ import {
|
||||
resetDialogDefaultOptions,
|
||||
} from '../function-call';
|
||||
|
||||
test('should update default options when calling setDefaultOptions method', () => {
|
||||
test('should update default options when calling setDefaultOptions method', async () => {
|
||||
const wrapper = document.createElement('div');
|
||||
const text = 'hello world';
|
||||
|
||||
setDialogDefaultOptions({ message: 'foo', teleport: wrapper, });
|
||||
showDialog();
|
||||
setDialogDefaultOptions({ message: text });
|
||||
showDialog({ teleport: wrapper });
|
||||
await later();
|
||||
const dialog = wrapper.querySelector('.van-dialog');
|
||||
expect(dialog.innerHTML.includes('foo')).toBeTruthy();
|
||||
|
||||
assert(dialog);
|
||||
expect(dialog.innerHTML.includes(text)).toBeTruthy();
|
||||
|
||||
resetDialogDefaultOptions();
|
||||
showDialog({ teleport: wrapper });
|
||||
await later();
|
||||
const dialog2 = wrapper.querySelector('.van-dialog');
|
||||
expect(dialog2.innerHTML.includes('foo')).toBeFalsy();
|
||||
|
||||
assert(dialog2);
|
||||
expect(dialog2.innerHTML.includes(text)).toBeFalsy();
|
||||
});
|
||||
|
||||
test('should render dialog after calling showDialog', async () => {
|
||||
@ -42,13 +47,14 @@ test('should close dialog after calling closeDialog', async () => {
|
||||
});
|
||||
|
||||
await later();
|
||||
const dialog = wrapper.querySelector('.van-dialog');
|
||||
const dialog = wrapper.querySelector('.van-dialog') as HTMLElement;
|
||||
|
||||
expect(dialog.style.display).toEqual('');
|
||||
|
||||
closeDialog();
|
||||
await later();
|
||||
expect(dialog.className.split(' ')).toContain(
|
||||
'van-dialog-bounce-leave-active'
|
||||
'van-dialog-bounce-leave-active',
|
||||
);
|
||||
});
|
||||
|
||||
@ -60,8 +66,8 @@ test('should allow to render JSX message', async () => {
|
||||
});
|
||||
|
||||
await later();
|
||||
const dialog = wrapper.querySelector('.van-dialog');
|
||||
const dialog = wrapper.querySelector('.van-dialog') as HTMLElement;
|
||||
expect(
|
||||
dialog.querySelector('.van-dialog__message').outerHTML
|
||||
dialog.querySelector('.van-dialog__message')?.outerHTML,
|
||||
).toMatchSnapshot();
|
||||
});
|
||||
@ -143,7 +143,7 @@ export default defineComponent({
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
useLockScroll(rootRef, () => props.lockScroll);
|
||||
useLockScroll(rootRef, () => props.lockScroll || dragging.value);
|
||||
|
||||
// useEventListener will set passive to `false` to eliminate the warning of Chrome
|
||||
useEventListener('touchmove', onTouchmove, { target: rootRef });
|
||||
|
||||
@ -88,7 +88,7 @@ By default, both the header and content areas of FloatingPanel can be dragged, b
|
||||
| anchors | Setting custom anchors, unit `px` | _number[]_ | `[100, window.innerWidth * 0.6]` |
|
||||
| duration | Transition duration, unit second | _number \| string_ | `0.3` |
|
||||
| content-draggable | Allow dragging content | _boolean_ | `true` |
|
||||
| lock-scroll `v4.6.4` | Whether to lock background scroll | _boolean_ | `false` |
|
||||
| lock-scroll `v4.6.4` | When not dragging, Whether to lock background scroll | _boolean_ | `false` |
|
||||
| safe-area-inset-bottom | Whether to enable bottom safe area adaptation | _boolean_ | `true` |
|
||||
|
||||
### Events
|
||||
|
||||
@ -88,7 +88,7 @@ export default {
|
||||
| anchors | 设置自定义锚点, 单位 `px` | _number[]_ | `[100, window.innerWidth * 0.6]` |
|
||||
| duration | 动画时长,单位秒,设置为 0 可以禁用动画 | _number \| string_ | `0.3` |
|
||||
| content-draggable | 允许拖拽内容容器 | _boolean_ | `true` |
|
||||
| lock-scroll `v4.6.4` | 是否锁定背景滚动 | _boolean_ | `false` |
|
||||
| lock-scroll `v4.6.4` | 当不拖拽时,是否锁定背景滚动 | _boolean_ | `false` |
|
||||
| safe-area-inset-bottom | 是否开启[底部安全区适配](#/zh-CN/advanced-usage#di-bu-an-quan-qu-gua-pei) | _boolean_ | `true` |
|
||||
|
||||
### Events
|
||||
|
||||
@ -92,8 +92,8 @@ export default {
|
||||
showConfirmDialog({
|
||||
title: 'Are you sure to delete?',
|
||||
})
|
||||
.then(resolve)
|
||||
.catch(resolve);
|
||||
.then(() => resolve(true))
|
||||
.catch(() => resolve(false));
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@ -99,8 +99,8 @@ export default {
|
||||
showConfirmDialog({
|
||||
title: '确定删除吗?',
|
||||
})
|
||||
.then(resolve)
|
||||
.catch(resolve);
|
||||
.then(() => resolve(true))
|
||||
.catch(() => resolve(false));
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@ -38,9 +38,13 @@ const beforeClose = ({ position }: { position: string }) => {
|
||||
case 'outside':
|
||||
return true;
|
||||
case 'right':
|
||||
return showConfirmDialog({
|
||||
title: t('confirm'),
|
||||
}) as Promise<boolean>;
|
||||
return new Promise<boolean>((resolve) => {
|
||||
showConfirmDialog({
|
||||
title: t('confirm'),
|
||||
})
|
||||
.then(() => resolve(true))
|
||||
.catch(() => resolve(false));
|
||||
});
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user