簡體   English   中英

material-ui BottomNavigation 不填充寬度

[英]material-ui BottomNavigation does not fill the width

我正在使用來自 Material ui 的 BottomNavigation,它有 5 個項目。 我認為無論手機/平板電腦的實際寬度如何,這 5 個項目都會始終顯示。 但是,當使用 chrome 在各種手機配置中進行測試時,我發現情況並非如此。 例如,請參見以下圖片:

在此處輸入圖片說明

在此處輸入圖片說明

我的代碼是:

import React from 'react';
import { BrowserRouter, Link, Route, Switch } from 'react-router-dom';


import { makeStyles } from '@material-ui/core/styles';
import BottomNavigation from '@material-ui/core/BottomNavigation';
import BottomNavigationAction from '@material-ui/core/BottomNavigationAction';
import ExploreOutlinedIcon from '@material-ui/icons/ExploreOutlined';
import RadioOutlinedIcon from '@material-ui/icons/RadioOutlined';
import PersonOutlineIcon from '@material-ui/icons/PersonOutline';
import SearchOutlinedIcon from '@material-ui/icons/SearchOutlined';
import MoreHorizOutlinedIcon from '@material-ui/icons/MoreHorizOutlined';
import NavigatorPane from './Components/NavigatorPane';



const useStyles = makeStyles({
    root: {
        width: '100%',
        position: 'fixed',
        bottom: 0,
    },
});



const App = () => {
    const classes = useStyles();
    const [value, setValue] = React.useState(0);

    return (
        <div>
            <BrowserRouter>
                <NavigatorPane></NavigatorPane>
                <BottomNavigation
                    value={value}
                    onChange={(event, newValue) => {
                        setValue(newValue);
                    }}
                    className={classes.root}
                >
                    <BottomNavigationAction component={Link} to="/explorer" label="Explore" icon={<ExploreOutlinedIcon />} />
                    <BottomNavigationAction component={Link} to="/radio" label="Radio" icon={<RadioOutlinedIcon />} />
                    <BottomNavigationAction component={Link} to="/mymusic" label="My Music" icon={<PersonOutlineIcon />} />
                    <BottomNavigationAction component={Link} to="/search" label="Search" icon={<SearchOutlinedIcon />} />
                    <BottomNavigationAction component={Link} to="/more" label="More" icon={<MoreHorizOutlinedIcon />} />

                </BottomNavigation>
            </BrowserRouter>
        </div>
    );
}

export default App;

我是 PWA/React/CSS 的新手,非常感謝您的指點。

這里的問題是BottomNavigationAction組件被設置為占用80px最小寬度 - 這就是它們在較小的屏幕中溢出的原因

在此處輸入圖片說明

我建議您使用媒體查詢來控制它

const useStyles = makeStyles({
  root: {
    width: "100%",
    position: "fixed",
    bottom: 0,
    "& .MuiBottomNavigationAction-root": {
      "@media (max-width: 768px)": {
        minWidth: "auto",
        padding: "6px 0"
      }
    }
  }
});

我正在使用相同的組件並遇到相同的問題,我通過將此樣式應用於根來解決它,如下所示

 root: {
    position: "fixed",
    bottom: "0px",
    left: "0px",
    right: "0px",
    width: "100%",
    height: "60px",
    backgroundColor: "#24242D"
  }

https://codesandbox.io/s/9xdc0?file=/demo.js

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM