Skip to content

Commit 3b8db4c

Browse files
authored
fix: fix editor tabs cannot scroll (#219)
1 parent a78594f commit 3b8db4c

File tree

4 files changed

+33
-30
lines changed

4 files changed

+33
-30
lines changed

src/components/scrollable/index.tsx

+28-15
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { prefixClaName, classNames } from 'mo/common/className';
66
export interface IScrollbarProps extends ScrollbarProps {
77
autoHideThumb?: boolean;
88
isShowShadow?: boolean;
9+
trackStyle?: React.CSSProperties;
910
}
1011

1112
const defaultSrollableClassName = prefixClaName('scrollbar');
@@ -16,7 +17,13 @@ const defaultSrollableClassName = prefixClaName('scrollbar');
1617
* https://github.com/xobotyi/react-scrollbars-custom/issues/46
1718
*/
1819
export function Scrollable(props: IScrollbarProps) {
19-
const { className, children, isShowShadow = false, ...custom } = props;
20+
const {
21+
className,
22+
children,
23+
isShowShadow = false,
24+
trackStyle,
25+
...custom
26+
} = props;
2027
const scroller = React.useRef<Scrollbar>(null);
2128

2229
const [isScrolling, setIsScrolling] = useState(false);
@@ -40,27 +47,33 @@ export function Scrollable(props: IScrollbarProps) {
4047

4148
const trackProps = useMemo(
4249
() => ({
43-
renderer: ({ elementRef, style, ...restProps }: any) => (
44-
<span
45-
{...restProps}
46-
ref={elementRef}
47-
style={{
48-
...style,
49-
opacity: isShow ? 1 : 0,
50-
transition: 'opacity 0.4s ease-in-out',
51-
}}
52-
onMouseEnter={onMouseEnter}
53-
onMouseLeave={onMouseLeave}
54-
/>
55-
),
50+
renderer: ({ elementRef, style, ...restProps }: any) => {
51+
// [TODO]: I don't know how to code it in a perfect way
52+
restProps.children.props.style.background = '#bfbfbf66';
53+
return (
54+
<span
55+
{...restProps}
56+
ref={elementRef}
57+
style={{
58+
...style,
59+
opacity: isShow ? 1 : 0,
60+
transition: 'opacity 0.4s ease-in-out',
61+
background: 'transparent',
62+
...trackStyle,
63+
}}
64+
/>
65+
);
66+
},
5667
}),
57-
[isShow, onMouseEnter, onMouseLeave]
68+
[isShow, trackStyle]
5869
);
5970

6071
return (
6172
<Scrollbar
6273
className={claNames}
6374
ref={scroller}
75+
onMouseEnter={onMouseEnter}
76+
onMouseLeave={onMouseLeave}
6477
{...(custom as any)}
6578
wrapperProps={{
6679
renderer: ({ elementRef, style, key, ...restProps }) => {

src/components/scrollable/style.scss

+3-5
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@ $react-custom-scrollbars: '.ScrollbarsCustom';
1717
}
1818

1919
#{$react-custom-scrollbars} {
20-
&-Scroller {
21-
height: 100%;
22-
}
23-
24-
&-Content {
20+
&-Scroller,
21+
&-Content,
22+
&-Wrapper {
2523
height: 100%;
2624
}
2725
}

src/components/tabs/style.scss

+1-8
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,15 @@
22

33
#{$tabs} {
44
height: 100%;
5-
height: 100%;
6-
overflow-x: auto;
7-
overflow-y: hidden;
85
position: relative;
96
user-select: none;
10-
width: 100%;
117

128
&__header {
139
align-items: center;
1410
display: flex;
1511
flex-flow: row nowrap;
1612
height: 35px;
1713
justify-content: flex-start;
18-
overflow: hidden;
19-
overflow-x: inherit;
20-
overflow-y: hidden;
21-
width: 100%;
2214
}
2315

2416
&__content {
@@ -43,6 +35,7 @@
4335
box-sizing: border-box;
4436
cursor: pointer;
4537
display: flex;
38+
flex: 0 0 auto;
4639
font-size: 13px;
4740
height: 100%;
4841
max-width: 300px;

src/workbench/editor/group.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,12 @@ export function EditorGroup(props: IEditorGroupProps & IEditorController) {
6262
<div className={groupClassName}>
6363
<div className={groupHeaderClassName}>
6464
<div className={groupTabsClassName}>
65-
<Scrollable>
65+
<Scrollable noScrollY trackStyle={{ height: 3 }}>
6666
<Tabs
6767
editable={true}
6868
type="card"
6969
data={data}
7070
onMoveTab={onMoveTab}
71-
style={{ overflow: 'hidden' }}
7271
onSelectTab={onSelectTab}
7372
onContextMenu={handleTabContextMenu}
7473
activeTab={isActiveGroup ? tab.id : ''}

0 commit comments

Comments
 (0)