diff --git a/src/dropdown-item/index.tsx b/src/dropdown-item/index.tsx index 8ef7917f9..c47c79fc6 100644 --- a/src/dropdown-item/index.tsx +++ b/src/dropdown-item/index.tsx @@ -7,7 +7,7 @@ import { } from 'vue'; // Utils -import { createNamespace, UnknownProp } from '../utils'; +import { createNamespace, getZIndexStyle, UnknownProp } from '../utils'; import { DROPDOWN_KEY, DropdownMenuProvide } from '../dropdown-menu'; // Composables @@ -153,9 +153,7 @@ export default createComponent({ closeOnClickOverlay, } = parent.props; - const style: CSSProperties = { - zIndex: zIndex !== undefined ? +zIndex : undefined, - }; + const style: CSSProperties = getZIndexStyle(zIndex); if (direction === 'down') { style.top = `${offset.value}px`; diff --git a/src/dropdown-menu/index.tsx b/src/dropdown-menu/index.tsx index d005bebae..cb7c3a2b9 100644 --- a/src/dropdown-menu/index.tsx +++ b/src/dropdown-menu/index.tsx @@ -70,11 +70,11 @@ export default createComponent({ children.some((item) => item.state.showWrapper) ); - const barStyle = computed(() => { + const barStyle = computed(() => { if (opened.value && isDef(props.zIndex)) { return { zIndex: +props.zIndex + 1, - } as CSSProperties; + }; } }); diff --git a/src/index-anchor/index.tsx b/src/index-anchor/index.tsx index 54bafda60..aa9c3798e 100644 --- a/src/index-anchor/index.tsx +++ b/src/index-anchor/index.tsx @@ -1,7 +1,7 @@ import { ref, reactive, computed, CSSProperties } from 'vue'; // Utils -import { createNamespace } from '../utils'; +import { createNamespace, getZIndexStyle } from '../utils'; import { BORDER_BOTTOM } from '../utils/constant'; import { INDEX_BAR_KEY, IndexBarProvide } from '../index-bar'; import { getScrollTop, getRootScrollTop } from '../utils/dom/scroll'; @@ -40,17 +40,19 @@ export default createComponent({ const isSticky = () => state.active && parent.props.sticky; - const anchorStyle = computed(() => { + const anchorStyle = computed(() => { const { zIndex, highlightColor } = parent.props; if (isSticky()) { return { - zIndex: `${zIndex}`, - left: state.left ? `${state.left}px` : null, - width: state.width ? `${state.width}px` : null, - transform: state.top ? `translate3d(0, ${state.top}px, 0)` : null, + ...getZIndexStyle(zIndex), + left: state.left ? `${state.left}px` : undefined, + width: state.width ? `${state.width}px` : undefined, + transform: state.top + ? `translate3d(0, ${state.top}px, 0)` + : undefined, color: highlightColor, - } as CSSProperties; + }; } }); diff --git a/src/index-bar/index.tsx b/src/index-bar/index.tsx index c92dc819d..93090b58f 100644 --- a/src/index-bar/index.tsx +++ b/src/index-bar/index.tsx @@ -85,19 +85,19 @@ export default createComponent({ linkChildren({ props }); - const sidebarStyle = computed(() => { + const sidebarStyle = computed(() => { if (isDef(props.zIndex)) { return { zIndex: +props.zIndex + 1, - } as CSSProperties; + }; } }); - const highlightStyle = computed(() => { + const highlightStyle = computed(() => { if (props.highlightColor) { return { color: props.highlightColor, - } as CSSProperties; + }; } }); diff --git a/src/index-bar/test/__snapshots__/demo.spec.ts.snap b/src/index-bar/test/__snapshots__/demo.spec.ts.snap index c0d6a8648..f6db8daa1 100644 --- a/src/index-bar/test/__snapshots__/demo.spec.ts.snap +++ b/src/index-bar/test/__snapshots__/demo.spec.ts.snap @@ -870,9 +870,7 @@ exports[`should render demo and match snapshot 1`] = `
-
+
Z
diff --git a/src/index-bar/test/__snapshots__/index.spec.js.snap b/src/index-bar/test/__snapshots__/index.spec.js.snap index 53de77a0a..e9c2f3d90 100644 --- a/src/index-bar/test/__snapshots__/index.spec.js.snap +++ b/src/index-bar/test/__snapshots__/index.spec.js.snap @@ -300,9 +300,7 @@ exports[`should update active anchor after page scroll 2`] = `
-
+
1
@@ -310,7 +308,7 @@ exports[`should update active anchor after page scroll 2`] = ` style="height: 10px;" >
2
diff --git a/src/nav-bar/index.tsx b/src/nav-bar/index.tsx index 08ef5c7f1..1dfd7f3e4 100644 --- a/src/nav-bar/index.tsx +++ b/src/nav-bar/index.tsx @@ -1,7 +1,7 @@ import { ref, CSSProperties } from 'vue'; // Utils -import { createNamespace } from '../utils'; +import { createNamespace, getZIndexStyle } from '../utils'; import { BORDER_BOTTOM } from '../utils/constant'; // Composables @@ -58,9 +58,7 @@ export default createComponent({ const renderNavBar = () => { const { title, fixed, border, zIndex } = props; - const style: CSSProperties = { - zIndex: zIndex !== undefined ? +zIndex : undefined, - }; + const style: CSSProperties = getZIndexStyle(zIndex); const hasLeft = props.leftArrow || props.leftText || slots.left; const hasRight = props.rightText || slots.right; diff --git a/src/number-keyboard/index.tsx b/src/number-keyboard/index.tsx index 29e8982bd..dce0ad21d 100644 --- a/src/number-keyboard/index.tsx +++ b/src/number-keyboard/index.tsx @@ -8,7 +8,7 @@ import { Transition, TeleportProps, } from 'vue'; -import { createNamespace, stopPropagation } from '../utils'; +import { createNamespace, getZIndexStyle, stopPropagation } from '../utils'; import { useClickAway } from '@vant/use'; import Key, { KeyType } from './Key'; @@ -263,9 +263,7 @@ export default createComponent({
{ const style: CSSProperties = { - zIndex: props.zIndex !== undefined ? +props.zIndex : undefined, + ...getZIndexStyle(props.zIndex), ...props.customStyle, }; diff --git a/src/tabbar/index.tsx b/src/tabbar/index.tsx index bf87f0238..a2c184e30 100644 --- a/src/tabbar/index.tsx +++ b/src/tabbar/index.tsx @@ -1,7 +1,7 @@ import { ref, PropType } from 'vue'; // Utils -import { createNamespace } from '../utils'; +import { createNamespace, getZIndexStyle } from '../utils'; import { BORDER_TOP_BOTTOM } from '../utils/constant'; import { callInterceptor, Interceptor } from '../utils/interceptor'; @@ -69,7 +69,7 @@ export default createComponent({ return (