Skip to content

Commit 224f1a4

Browse files
committed
Add persistentScrollbar props, example, test and doc
1 parent f1901f1 commit 224f1a4

File tree

9 files changed

+57
-306
lines changed

9 files changed

+57
-306
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ This prop will override any value given to heightRelativeToParent when setting t
6363
- **rtl** : boolean, default false. Right to left document, will place the custom scrollbar on the left side of the content, and assume the native one is also there.
6464
- **scrollTo**: number, default undefined. Will scroll content to the given value.
6565
- **keepAtBottom**: boolean, default false. For dynamic content, will keep the scroll position at the bottom of the content, when the content changes, if the position was at the bottom before the change. [See example here](http://rommguy.github.io/react-custom-scroll/example/demo.html?dynamic=true)
66+
- **persistentScrollbar**: boolean, default false. When true, scrollbar will show even while the content is not hovered.
6667
- **className**: string, default undefined. Allows adding your own class name to the root element.
6768

6869
##### Example for heightRelativeToParent

dist/customScroll.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/reactCustomScroll.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/exampleDist/example.js

+2-302
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/exampleDist/example.js.LICENSE.txt

+24
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
/*!************************!*\
2+
!*** external "react" ***!
3+
\************************/
4+
5+
/*!**************************!*\
6+
!*** ./src/main/cs.scss ***!
7+
\**************************/
8+
9+
/*!****************************!*\
10+
!*** external "react-dom" ***!
11+
\****************************/
12+
13+
/*!*****************************!*\
14+
!*** external "prop-types" ***!
15+
\*****************************/
16+
17+
/*!**********************************!*\
18+
!*** ./src/main/customScroll.js ***!
19+
\**********************************/
20+
21+
/*!************************************!*\
22+
!*** ./src/main/simpleDebounce.js ***!
23+
\************************************/
24+
125
/**
226
* @license
327
* Lodash <https://lodash.com/>

example/firstComp/firstComp.js

+14
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,20 @@ export class FirstComp extends Component {
8080
</CustomScroll>
8181
</div>
8282
</div>
83+
<div key="persistent-example" className="container custom-scroll-example">
84+
<label className="side-title">Persistent Scroll</label>
85+
86+
<div className="panel">
87+
<div className="panel-header">
88+
<label className="panel-title">Hover or not, I'm here!</label>
89+
</div>
90+
<CustomScroll allowOuterScroll={true} persistentScrollbar>
91+
<div className="panel-content-custom panel-content">
92+
<div className="content-fill">{this.getText()}</div>
93+
</div>
94+
</CustomScroll>
95+
</div>
96+
</div>
8397
<div key="crazy-example" className="container custom-scroll-example">
8498
<label className="side-title">Crazy Designer</label>
8599

src/main/cs.scss

+4
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@
6969
}
7070
}
7171

72+
.persistent-scrollbar {
73+
opacity: 1;
74+
}
75+
7276
&.scroll-handle-dragged .custom-scrollbar {
7377
opacity: 1;
7478
}

src/main/customScroll.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,8 @@ class CustomScroll extends Component {
368368
<div className={styles.positioning}>
369369
<div
370370
ref={this.customScrollbarRef}
371-
className={`${styles.customScrollbar} ${this.props.rtl ? styles.customScrollbarRtl : ''}`}
372-
key="scrollbar"
371+
className={`${styles.customScrollbar} ${this.props.rtl ? styles.customScrollbarRtl : ''} ${this.props.persistentScrollbar ? styles.persistentScrollbar : ''}`}
372+
key='scrollbar'
373373
>
374374
<div ref={this.scrollHandleRef} className={styles.customScrollHandle} style={scrollHandleStyle}>
375375
<div className={this.props.handleClass} />
@@ -408,6 +408,7 @@ try {
408408
rtl: PropTypes.bool,
409409
scrollTo: PropTypes.number,
410410
keepAtBottom: PropTypes.bool,
411+
persistentScrollbar: PropTypes.bool,
411412
className: PropTypes.string
412413
}
413414
} catch (e) {} //eslint-disable-line no-empty

src/test/customScroll.spec.js

+7
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,13 @@ describe('custom scroll', function () {
199199
})
200200
})
201201
})
202+
203+
describe('persistentScrollbar is injected to class', function(){
204+
it('class rcs-persistent-scrollbar should be inejcted to customScrollbar is props.persistentScrollbar is true', function () {
205+
const customScroll = renderCustomScroll(customScrollContainer, { persistentScrollbar: true }, visibleHeight, totalScrollHeight)
206+
expect(customScroll.customScrollbarRef.current).toHaveClass('rcs-persistent-scrollbar')
207+
})
208+
})
202209
})
203210

204211
describe('freeze position', function () {

0 commit comments

Comments
 (0)