fix(ActionSheet): should not reopen when closed (#8271)

This commit is contained in:
neverland 2021-03-04 19:40:30 +08:00 committed by GitHub
parent 4cd4818bb4
commit 0093e19bf7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 4 deletions

View File

@ -1,3 +1,5 @@
import Vue from 'vue';
// Utils
import { createNamespace } from '../utils';
import { emit, inherit } from '../utils/functional';
@ -89,11 +91,13 @@ function ActionSheet(
callback(item);
}
emit(ctx, 'select', item, index);
if (props.closeOnClickAction) {
emit(ctx, 'input', false);
}
Vue.nextTick(() => {
emit(ctx, 'select', item, index);
});
}
function OptionContent() {

View File

@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`callback events 1`] = `
<div class="van-popup van-popup--round van-popup--bottom van-popup--safe-area-inset-bottom van-action-sheet" name="van-popup-slide-bottom">
<div class="van-popup van-popup--round van-popup--bottom van-popup--safe-area-inset-bottom van-action-sheet" name="van-popup-slide-bottom" style="z-index: 2002;">
<div class="van-action-sheet__content"><button type="button" class="van-action-sheet__item"><span class="van-action-sheet__name">Option</span></button><button type="button" class="van-action-sheet__item van-action-sheet__item--disabled"><span class="van-action-sheet__name">Option</span></button><button type="button" class="van-action-sheet__item van-action-sheet__item--loading">
<div class="van-loading van-loading--circular van-action-sheet__loading-icon"><span class="van-loading__spinner van-loading__spinner--circular"><svg viewBox="25 25 50 50" class="van-loading__circular"><circle cx="50" cy="50" r="20" fill="none"></circle></svg></span></div>
</button><button type="button" class="van-action-sheet__item"><span class="van-action-sheet__name">Option</span>

View File

@ -1,7 +1,7 @@
import { mount, later } from '../../../test';
import ActionSheet from '..';
test('callback events', () => {
test('callback events', async () => {
const callback = jest.fn();
const onInput = jest.fn();
const onCancel = jest.fn();
@ -34,6 +34,8 @@ test('callback events', () => {
options.at(1).trigger('click');
wrapper.find('.van-action-sheet__cancel').trigger('click');
await later();
expect(callback).toHaveBeenCalled();
expect(onCancel).toHaveBeenCalled();
expect(onInput).toHaveBeenCalledWith(false);