add scroll to TopBar buttons
This commit is contained in:
@ -2,7 +2,7 @@ import { Box, Button, Tab, Tabs, Typography } from '@mui/material';
|
|||||||
import CloseRoundedIcon from '@mui/icons-material/CloseRounded';
|
import CloseRoundedIcon from '@mui/icons-material/CloseRounded';
|
||||||
import { useLocation, useNavigate } from 'react-router-dom';
|
import { useLocation, useNavigate } from 'react-router-dom';
|
||||||
import ArrowBackRoundedIcon from '@mui/icons-material/ArrowBackRounded';
|
import ArrowBackRoundedIcon from '@mui/icons-material/ArrowBackRounded';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useRef, useState } from 'react';
|
||||||
import { Tooltip } from '@mui/material';
|
import { Tooltip } from '@mui/material';
|
||||||
import { fetchCoins } from '../api';
|
import { fetchCoins } from '../api';
|
||||||
import CustomTooltip from './CustomTooltip';
|
import CustomTooltip from './CustomTooltip';
|
||||||
@ -35,6 +35,7 @@ export default function TopBar({ onRegister, username }: TopBarProps) {
|
|||||||
const [coins, setCoins] = useState<number>(0);
|
const [coins, setCoins] = useState<number>(0);
|
||||||
const [value, setValue] = useState(0);
|
const [value, setValue] = useState(0);
|
||||||
const [activePage, setActivePage] = useState('versions');
|
const [activePage, setActivePage] = useState('versions');
|
||||||
|
const tabsWrapperRef = useRef<HTMLDivElement | null>(null);
|
||||||
|
|
||||||
const handleChange = (event: React.SyntheticEvent, newValue: number) => {
|
const handleChange = (event: React.SyntheticEvent, newValue: number) => {
|
||||||
setValue(newValue);
|
setValue(newValue);
|
||||||
@ -53,6 +54,23 @@ export default function TopBar({ onRegister, username }: TopBarProps) {
|
|||||||
navigate('/');
|
navigate('/');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleTabsWheel = (event: React.WheelEvent<HTMLDivElement>) => {
|
||||||
|
// чтобы страница не скроллилась вертикально
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
if (!tabsWrapperRef.current) return;
|
||||||
|
|
||||||
|
// Находим внутренний скроллер MUI Tabs
|
||||||
|
const scroller = tabsWrapperRef.current.querySelector(
|
||||||
|
'.MuiTabs-scroller'
|
||||||
|
) as HTMLDivElement | null;
|
||||||
|
|
||||||
|
if (!scroller) return;
|
||||||
|
|
||||||
|
// Прокручиваем горизонтально, используя вертикальный скролл мыши
|
||||||
|
scroller.scrollLeft += event.deltaY * 0.3;
|
||||||
|
};
|
||||||
|
|
||||||
// const getPageTitle = () => {
|
// const getPageTitle = () => {
|
||||||
// if (isLoginPage) {
|
// if (isLoginPage) {
|
||||||
// return 'Вход';
|
// return 'Вход';
|
||||||
@ -159,6 +177,8 @@ export default function TopBar({ onRegister, username }: TopBarProps) {
|
|||||||
)}
|
)}
|
||||||
{!isLaunchPage && !isRegistrationPage && !isLoginPage && (
|
{!isLaunchPage && !isRegistrationPage && !isLoginPage && (
|
||||||
<Box
|
<Box
|
||||||
|
ref={tabsWrapperRef}
|
||||||
|
onWheel={handleTabsWheel}
|
||||||
sx={{
|
sx={{
|
||||||
borderBottom: 1,
|
borderBottom: 1,
|
||||||
borderColor: 'transparent',
|
borderColor: 'transparent',
|
||||||
@ -171,7 +191,10 @@ export default function TopBar({ onRegister, username }: TopBarProps) {
|
|||||||
value={value}
|
value={value}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
aria-label="basic tabs example"
|
aria-label="basic tabs example"
|
||||||
|
variant="scrollable"
|
||||||
|
scrollButtons={false}
|
||||||
disableRipple={true}
|
disableRipple={true}
|
||||||
|
sx={{ maxWidth: "42vw"}}
|
||||||
>
|
>
|
||||||
<Tab
|
<Tab
|
||||||
label="Версии"
|
label="Версии"
|
||||||
|
|||||||
Reference in New Issue
Block a user