Skip to content

Commit

Permalink
Merge pull request #677 from Stremio/feature-double-click-scroll-top
Browse files Browse the repository at this point in the history
feature: add onDoubleClick function for scrollTop on NavBarButton
  • Loading branch information
jaruba authored Sep 18, 2024
2 parents e7dbff4 + 011ecd2 commit c956dc4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/common/Button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const classnames = require('classnames');
const styles = require('./styles');
const { useLongPress } = require('use-long-press');

const Button = React.forwardRef(({ className, href, disabled, children, onLongPress, ...props }, ref) => {
const Button = React.forwardRef(({ className, href, disabled, children, onLongPress, onDoubleClick, ...props }, ref) => {
const longPress = useLongPress(onLongPress, { detect: 'pointer' });
const onKeyDown = React.useCallback((event) => {
if (typeof props.onKeyDown === 'function') {
Expand Down Expand Up @@ -42,6 +42,7 @@ const Button = React.forwardRef(({ className, href, disabled, children, onLongPr
href,
onKeyDown,
onMouseDown,
onDoubleClick,
...longPress()
},
children
Expand All @@ -58,6 +59,7 @@ Button.propTypes = {
onKeyDown: PropTypes.func,
onMouseDown: PropTypes.func,
onLongPress: PropTypes.func,
onDoubleClick: PropTypes.func
};

module.exports = Button;
11 changes: 10 additions & 1 deletion src/common/NavBar/VerticalNavBar/NavTabButton/NavTabButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,17 @@ const NavTabButton = ({ className, logo, icon, label, href, selected, onClick })
:
null
), [icon]);
const onDoubleClick = () => {
const scrollableElements = document.querySelectorAll('div');

scrollableElements.forEach((element) => {
if (element.scrollTop > 0) {
element.scrollTop = 0;
}
});
};
return (
<Button className={classnames(className, styles['nav-tab-button-container'], { 'selected': selected })} title={label} tabIndex={-1} href={href} onClick={onClick}>
<Button className={classnames(className, styles['nav-tab-button-container'], { 'selected': selected })} title={label} tabIndex={-1} href={href} onClick={onClick} onDoubleClick={onDoubleClick}>
{
typeof logo === 'string' && logo.length > 0 ?
<Image
Expand Down

0 comments on commit c956dc4

Please sign in to comment.