Skip to content

Commit

Permalink
feat(scrollbar): add zIndex api (#2687)
Browse files Browse the repository at this point in the history
  • Loading branch information
zyprepare committed Dec 5, 2023
1 parent d0b76ec commit 2fa5ee5
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/good-jobs-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/scrollbar": minor
---

feat: add zIndex api
5 changes: 5 additions & 0 deletions .changeset/old-falcons-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/hiui": patch
---

feat(scrollbar): add zIndex api
11 changes: 10 additions & 1 deletion packages/ui/scrollbar/src/Scrollbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const Scrollbar = forwardRef<HTMLDivElement | null, ScrollbarProps>(
className,
children,
style,
zIndex,
innerRef,
...rest
},
Expand All @@ -43,8 +44,11 @@ export const Scrollbar = forwardRef<HTMLDivElement | null, ScrollbarProps>(
useEffect(() => {
if (containerElement) {
setPs(new PerfectScrollbar(containerElement))

// 动态设置滚动条 z-index
zIndex && containerElement.style.setProperty('--scrollbar-zIndex', String(zIndex))
}
}, [containerElement])
}, [containerElement, zIndex])

// 轴定制
useEffect(() => {
Expand Down Expand Up @@ -148,6 +152,11 @@ export interface ScrollbarProps extends HiBaseHTMLProps<'div'>, ScrollbarEventPr
* @default 'relative'
*/
position?: ScrollbarPositionEnum
/**
* 设置滚动条 z-index
* @default 'auto'
*/
zIndex?: number | string
/**
* 开启滚动的轴
* @default 'both'
Expand Down
7 changes: 7 additions & 0 deletions packages/ui/scrollbar/src/styles/scrollbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
$prefix: '#{$component-prefix}-scrollbar' !default;

.#{$prefix} {
--scrollbar-zIndex: 'auto';

overflow: hidden;
width: 100%;
height: 100%;
Expand Down Expand Up @@ -94,4 +96,9 @@ $prefix: '#{$component-prefix}-scrollbar' !default;
opacity: 0;
}
}

> .ps__thumb-y,
> .ps__thumb-x {
z-index: var(--scrollbar-zIndex);
}
}

0 comments on commit 2fa5ee5

Please sign in to comment.