feature: add onDoubleClick function to scrolltop

This commit is contained in:
Timothy Z. 2024-08-27 13:43:25 +03:00
parent 2b60b3a5f0
commit 48e44a0332
2 changed files with 13 additions and 2 deletions

View file

@ -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') {
@ -42,6 +42,7 @@ const Button = React.forwardRef(({ className, href, disabled, children, onLongPr
href,
onKeyDown,
onMouseDown,
onDoubleClick,
...longPress()
},
children
@ -58,6 +59,7 @@ Button.propTypes = {
onKeyDown: PropTypes.func,
onMouseDown: PropTypes.func,
onLongPress: PropTypes.func,
onDoubleClick: PropTypes.func
};
module.exports = Button;

View file

@ -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.scrollHeight > element.clientHeight) {
element.scrollTo(0, 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