diff --git a/src/index-anchor/index.less b/src/index-anchor/index.less index cdc7a0b26..078819ada 100644 --- a/src/index-anchor/index.less +++ b/src/index-anchor/index.less @@ -1,6 +1,7 @@ @import '../style/var'; .van-index-anchor { + z-index: @index-anchor-z-index; box-sizing: border-box; padding: @index-anchor-padding; color: @index-anchor-text-color; diff --git a/src/index-bar/index.js b/src/index-bar/index.js index cca4e7466..d37a95347 100644 --- a/src/index-bar/index.js +++ b/src/index-bar/index.js @@ -1,5 +1,5 @@ // Utils -import { createNamespace } from '../utils'; +import { createNamespace, isDef } from '../utils'; import { GREEN } from '../utils/constant'; import { isHidden } from '../utils/dom/style'; import { preventDefault } from '../utils/dom/event'; @@ -43,14 +43,11 @@ export default createComponent({ ], props: { + zIndex: Number, sticky: { type: Boolean, default: true, }, - zIndex: { - type: Number, - default: 1, - }, highlightColor: { type: String, default: GREEN, @@ -72,6 +69,14 @@ export default createComponent({ }, computed: { + sidebarStyle() { + if (isDef(this.zIndex)) { + return { + zIndex: this.zIndex + 1, + }; + } + }, + highlightStyle() { const { highlightColor } = this; if (highlightColor) { @@ -237,7 +242,7 @@ export default createComponent({
-
ABCDEFGHIJKLMNOPQRSTUVWXYZ
+
ABCDEFGHIJKLMNOPQRSTUVWXYZ
A
diff --git a/src/index-bar/test/__snapshots__/index.spec.js.snap b/src/index-bar/test/__snapshots__/index.spec.js.snap index 81a0d7029..f038eef00 100644 --- a/src/index-bar/test/__snapshots__/index.spec.js.snap +++ b/src/index-bar/test/__snapshots__/index.spec.js.snap @@ -2,7 +2,7 @@ exports[`custom anchor text 1`] = `
-
ABCDEFGHIJKLMNOPQRSTUVWXYZ
+
ABCDEFGHIJKLMNOPQRSTUVWXYZ
Title A
@@ -14,7 +14,7 @@ exports[`custom anchor text 1`] = ` exports[`scroll and update active anchor 1`] = `
-
ABCDEFGHIJKLMNOPQRSTUVWXYZ
+
ABCDEFGHIJKLMNOPQRSTUVWXYZ
1
@@ -32,12 +32,12 @@ exports[`scroll and update active anchor 1`] = ` exports[`scroll and update active anchor 2`] = `
-
ABCDEFGHIJKLMNOPQRSTUVWXYZ
+
ABCDEFGHIJKLMNOPQRSTUVWXYZ
-
1
+
1
-
2
+
2
3
diff --git a/src/style/var.less b/src/style/var.less index acdbf9af5..a88f96f35 100644 --- a/src/style/var.less +++ b/src/style/var.less @@ -369,6 +369,7 @@ @goods-action-button-danger-color: @gradient-red; // IndexAnchor +@index-anchor-z-index: 1; @index-anchor-padding: 0 @padding-md; @index-anchor-text-color: @text-color; @index-anchor-font-weight: @font-weight-bold; @@ -378,6 +379,7 @@ @index-anchor-sticky-background-color: @white; // IndexBar +@index-bar-sidebar-z-index: 2; @index-bar-index-font-size: @font-size-xs; @index-bar-index-line-height: 14px;