From 83aa18ee3a89b5af7bbe32ec90306d25e54eb4b5 Mon Sep 17 00:00:00 2001 From: Mrbigshot <1994yechen@gmail.com> Date: Thu, 26 Mar 2026 22:44:59 +0800 Subject: [PATCH] feat(Popup): export useGlobalZIndex and setGlobalZIndex (#13789) Co-authored-by: cye2 --- packages/vant/src/popup/index.ts | 4 +++ packages/vant/src/popup/test/index.spec.jsx | 28 ++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/packages/vant/src/popup/index.ts b/packages/vant/src/popup/index.ts index 52a2ad6c4..fb988ef2b 100644 --- a/packages/vant/src/popup/index.ts +++ b/packages/vant/src/popup/index.ts @@ -4,6 +4,10 @@ import _Popup from './Popup'; export const Popup = withInstall(_Popup); export default Popup; export { popupProps } from './Popup'; +export { + useGlobalZIndex, + setGlobalZIndex, +} from '../composables/use-global-z-index'; export type { PopupProps } from './Popup'; export type { PopupPosition, diff --git a/packages/vant/src/popup/test/index.spec.jsx b/packages/vant/src/popup/test/index.spec.jsx index 4ff75ff87..36566d2cf 100644 --- a/packages/vant/src/popup/test/index.spec.jsx +++ b/packages/vant/src/popup/test/index.spec.jsx @@ -1,6 +1,6 @@ import { nextTick } from 'vue'; import { mount, triggerDrag } from '../../../test'; -import { Popup } from '..'; +import { Popup, useGlobalZIndex, setGlobalZIndex } from '..'; let wrapper; afterEach(() => { @@ -303,3 +303,29 @@ test('should destroy content when using destroyOnClose prop', async () => { await wrapper.setProps({ show: false }); expect(wrapper.find('.foo').exists()).toBeFalsy(); }); + +test('useGlobalZIndex should return auto-incrementing z-index', () => { + setGlobalZIndex(2000); + const first = useGlobalZIndex(); + const second = useGlobalZIndex(); + const third = useGlobalZIndex(); + expect(first).toBe(2001); + expect(second).toBe(2002); + expect(third).toBe(2003); +}); + +test('setGlobalZIndex should reset the global z-index', () => { + setGlobalZIndex(100); + expect(useGlobalZIndex()).toBe(101); + expect(useGlobalZIndex()).toBe(102); + + setGlobalZIndex(500); + expect(useGlobalZIndex()).toBe(501); + expect(useGlobalZIndex()).toBe(502); +}); + +test('setGlobalZIndex should allow custom initial value', () => { + setGlobalZIndex(0); + expect(useGlobalZIndex()).toBe(1); + expect(useGlobalZIndex()).toBe(2); +});