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

fix(CustomScrollView): use default scrollbar if hasPointer=false #6437

Merged
merged 2 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,6 @@
overflow-x: hidden;
padding-inline-end: 100px;
position: relative;

/**
* Для удаление скролла в Firefox.
* В версии ниже 64 будет виден скролл, но это не ломает функциональность.
*/
scrollbar-width: none;
}

.CustomScrollView__box::-webkit-scrollbar {
display: none;
}

.CustomScrollView__barY:active + .CustomScrollView__box {
Expand Down Expand Up @@ -83,3 +73,42 @@
:global(.vkuiInternalCustomSelectDropdown--wide) .CustomScrollView__box {
padding-inline-end: 0;
}

.CustomScrollView--hasPointer-true .CustomScrollView__box {
/**
* Для удаление скролла в Firefox.
* В версии ниже 64 будет виден скролл, но это не ломает функциональность.
*/
scrollbar-width: none;
}

.CustomScrollView--hasPointer-true .CustomScrollView__box::-webkit-scrollbar {
display: none;
}

@media (--pointer-has) {
.CustomScrollView--hasPointer-none .CustomScrollView__box {
/**
* Для удаление скролла в Firefox.
* В версии ниже 64 будет виден скролл, но это не ломает функциональность.
*/
scrollbar-width: none;
}

.CustomScrollView--hasPointer-none .CustomScrollView__box::-webkit-scrollbar {
display: none;
}
}

/**
* Не отрисовываем полосу прокрутки, если у устройства отсутствует мышь
*/
.CustomScrollView--hasPointer-false .CustomScrollView__barY {
display: none;
}

@media (--pointer-has-not) {
.CustomScrollView--hasPointer-none .CustomScrollView__barY {
display: none;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';
import { classNames } from '@vkontakte/vkjs';
import { useAdaptivity } from '../../hooks/useAdaptivity';
import { useEventListener } from '../../hooks/useEventListener';
import { useExternRef } from '../../hooks/useExternRef';
import { useDOM } from '../../lib/dom';
Expand All @@ -9,6 +10,17 @@
import { TrackerOptionsProps, useTrackerVisibility } from './useTrackerVisibility';
import styles from './CustomScrollView.module.css';

function hasPointerClassName(hasPointer: boolean | undefined) {
inomdzhon marked this conversation as resolved.
Show resolved Hide resolved
switch (hasPointer) {
case undefined:
return styles['CustomScrollView--hasPointer-none'];
case false:
return styles['CustomScrollView--hasPointer-false'];

Check warning on line 18 in packages/vkui/src/components/CustomScrollView/CustomScrollView.tsx

View check run for this annotation

Codecov / codecov/patch

packages/vkui/src/components/CustomScrollView/CustomScrollView.tsx#L17-L18

Added lines #L17 - L18 were not covered by tests
}

return styles['CustomScrollView--hasPointer-true'];
SevereCloud marked this conversation as resolved.
Show resolved Hide resolved
}

export interface CustomScrollViewProps
extends React.AllHTMLAttributes<HTMLDivElement>,
HasRootRef<HTMLDivElement>,
Expand All @@ -32,6 +44,7 @@
...restProps
}: CustomScrollViewProps) => {
const { document, window } = useDOM();
const { hasPointer } = useAdaptivity();

const ratio = React.useRef(NaN);
const lastTrackerTop = React.useRef(0);
Expand Down Expand Up @@ -181,7 +194,7 @@

return (
<div
className={classNames(styles['CustomScrollView'], className)}
className={classNames(className, styles['CustomScrollView'], hasPointerClassName(hasPointer))}
ref={getRootRef}
{...restProps}
>
Expand Down
Loading