admin管理员组文章数量:1332389
fairly new to the coding space. I have tried looking everywhere for the answer to this question, and while I've found many answers, none of them work for me.
My problem is that I would like to use @Material-UI tab ponents as a NavBar, and I can only seem to either 1. turn the tabs into static links that work but have no animation or indicator, or 2. keep the animations but have no functionality as far as changing the page goes.
I have tried this, this, this, and more, and many of the answers found within each of those.
Edit: Here is a Git Repo.
Here is my NavBar ponent, currently on status #2 where it has animations but not functionality:
import React from 'react';
import { Paper, Tabs, Tab } from '@material-ui/core';
const navStyle= {
backgroundColor: '#220000',
color: '#fff',
}
export class NavBar extends React.Component {
state = {
value: 0,
};
handleChange = (event, value) => {
event.preventDefault();
this.setState({ value });
console.log(value)
};
render() {
return (
<div>
<Paper>
<Tabs
value={this.state.value}
onChange={this.handleChange}
indicatorColor={"secondary"}
// textColor="secondary"
centered
style={navStyle}
>
<Tab label="Home" href='/' />
<Tab label="About" href='/about' />
</Tabs>
</Paper>
</div>
)}
}
dependencies:
"@material-ui/core": "^1.3.1",
"history": "^4.7.2",
"prop-types": "^15.6.2",
"react": "^16.4.1",
"react-dom": "^16.4.1",
"react-router-dom": "^4.3.1",
"react-scripts": "1.1.4"
fairly new to the coding space. I have tried looking everywhere for the answer to this question, and while I've found many answers, none of them work for me.
My problem is that I would like to use @Material-UI tab ponents as a NavBar, and I can only seem to either 1. turn the tabs into static links that work but have no animation or indicator, or 2. keep the animations but have no functionality as far as changing the page goes.
I have tried this, this, this, and more, and many of the answers found within each of those.
Edit: Here is a Git Repo.
Here is my NavBar ponent, currently on status #2 where it has animations but not functionality:
import React from 'react';
import { Paper, Tabs, Tab } from '@material-ui/core';
const navStyle= {
backgroundColor: '#220000',
color: '#fff',
}
export class NavBar extends React.Component {
state = {
value: 0,
};
handleChange = (event, value) => {
event.preventDefault();
this.setState({ value });
console.log(value)
};
render() {
return (
<div>
<Paper>
<Tabs
value={this.state.value}
onChange={this.handleChange}
indicatorColor={"secondary"}
// textColor="secondary"
centered
style={navStyle}
>
<Tab label="Home" href='/' />
<Tab label="About" href='/about' />
</Tabs>
</Paper>
</div>
)}
}
dependencies:
"@material-ui/core": "^1.3.1",
"history": "^4.7.2",
"prop-types": "^15.6.2",
"react": "^16.4.1",
"react-dom": "^16.4.1",
"react-router-dom": "^4.3.1",
"react-scripts": "1.1.4"
Share
edited Jul 13, 2018 at 1:30
Brittany G
asked Jul 12, 2018 at 20:30
Brittany GBrittany G
731 silver badge4 bronze badges
0
1 Answer
Reset to default 6You could make your Tab
ponents into React Router Link
ponents the same way that it is done in the first example you linked.
Just make sure not to preventDefault
on the handleChange
event, since that would stop the links from working.
Example
class App extends React.Component {
state = {
value: 0
};
handleChange = (event, value) => {
this.setState({ value });
};
render() {
return (
<BrowserRouter>
<div>
<Paper>
<Tabs
value={this.state.value}
onChange={this.handleChange}
indicatorColor={"secondary"}
centered
style={navStyle}
>
<Tab label="Home" to="/" ponent={Link} />
<Tab label="About" to="/about" ponent={Link} />
</Tabs>
</Paper>
<Switch>
<Route exact path="/" ponent={Home} />
<Route path="/about" ponent={About} />
</Switch>
</div>
</BrowserRouter>
);
}
}
本文标签: javascriptUsing MaterialUI Tabs as NavbarStack Overflow
版权声明:本文标题:javascript - Using @Material-UI Tabs as Navbar - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742290211a2447655.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论