Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add persistentScrollbar props, example, test and doc #103

Open
wants to merge 2 commits into
base: gh-pages
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ This prop will override any value given to heightRelativeToParent when setting t
- **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.
- **scrollTo**: number, default undefined. Will scroll content to the given value.
- **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)
- **persistentScrollbar**: boolean, default false. When true, scrollbar will show even while the content is not hovered.
- **className**: string, default undefined. Allows adding your own class name to the root element.

##### Example for heightRelativeToParent
Expand Down
2 changes: 1 addition & 1 deletion dist/customScroll.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/reactCustomScroll.js

Large diffs are not rendered by default.

304 changes: 2 additions & 302 deletions example/exampleDist/example.js

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions example/exampleDist/example.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
/*!************************!*\
!*** external "react" ***!
\************************/

/*!**************************!*\
!*** ./src/main/cs.scss ***!
\**************************/

/*!****************************!*\
!*** external "react-dom" ***!
\****************************/

/*!*****************************!*\
!*** external "prop-types" ***!
\*****************************/

/*!**********************************!*\
!*** ./src/main/customScroll.js ***!
\**********************************/

/*!************************************!*\
!*** ./src/main/simpleDebounce.js ***!
\************************************/

/**
* @license
* Lodash <https://lodash.com/>
Expand Down
14 changes: 14 additions & 0 deletions example/firstComp/firstComp.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ export class FirstComp extends Component {
</CustomScroll>
</div>
</div>
<div key="persistent-example" className="container custom-scroll-example">
<label className="side-title">Persistent Scroll</label>

<div className="panel">
<div className="panel-header">
<label className="panel-title">Hover or not, I'm here!</label>
</div>
<CustomScroll allowOuterScroll={true} persistentScrollbar>
<div className="panel-content-custom panel-content">
<div className="content-fill">{this.getText()}</div>
</div>
</CustomScroll>
</div>
</div>
<div key="crazy-example" className="container custom-scroll-example">
<label className="side-title">Crazy Designer</label>

Expand Down
4 changes: 4 additions & 0 deletions src/main/cs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@
}
}

.persistent-scrollbar {
opacity: 1;
}

&.scroll-handle-dragged .custom-scrollbar {
opacity: 1;
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/customScroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,8 @@ class CustomScroll extends Component {
<div className={styles.positioning}>
<div
ref={this.customScrollbarRef}
className={`${styles.customScrollbar} ${this.props.rtl ? styles.customScrollbarRtl : ''}`}
key="scrollbar"
className={`${styles.customScrollbar} ${this.props.rtl ? styles.customScrollbarRtl : ''} ${this.props.persistentScrollbar ? styles.persistentScrollbar : ''}`}
key='scrollbar'
>
<div ref={this.scrollHandleRef} className={styles.customScrollHandle} style={scrollHandleStyle}>
<div className={this.props.handleClass} />
Expand Down Expand Up @@ -408,6 +408,7 @@ try {
rtl: PropTypes.bool,
scrollTo: PropTypes.number,
keepAtBottom: PropTypes.bool,
persistentScrollbar: PropTypes.bool,
className: PropTypes.string
}
} catch (e) {} //eslint-disable-line no-empty
Expand Down
7 changes: 7 additions & 0 deletions src/test/customScroll.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,13 @@ describe('custom scroll', function () {
})
})
})

describe('persistentScrollbar is injected to class', function(){
it('class rcs-persistent-scrollbar should be inejcted to customScrollbar is props.persistentScrollbar is true', function () {
const customScroll = renderCustomScroll(customScrollContainer, { persistentScrollbar: true }, visibleHeight, totalScrollHeight)
expect(customScroll.customScrollbarRef.current).toHaveClass('rcs-persistent-scrollbar')
})
})
})

describe('freeze position', function () {
Expand Down