- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Semantic-UI-React 和 Semantic-UI 编写 Web 应用程序。我正在处理的页面大部分是静态的,但我想用 Semantic-UI-React 替换下拉菜单和侧边栏,而不是使用 jQuery。但是,菜单(下拉菜单所在的菜单)和侧边栏是完全不同的组件,我不确定如何从菜单中打开侧边栏(无需将所有页面内容嵌套在侧边栏推送器内容中)。谢谢!
这是我正在尝试做的事情的示例:
import React, { Component } from 'react'
import { Sidebar, Segment, Button, Menu, Image, Icon, Header } from 'semantic-ui-react'
class SidebarBottomOverlay extends Component {
constructor(props) {
super(props);
this.state = {
visible: false,
};
this.toggleVisibility = this.toggleVisibility.bind(this);
}
toggleVisibility = () => this.setState({ visible: !this.state.visible })
get MyButton() {
return(
<Button onClick={this.toggleVisibility}>Togglevis2</Button>
)
}
render() {
const { visible } = this.state
return (
<div>
<Button onClick={this.toggleVisibility.bind(this)}>Toggle Visibility</Button>
<Sidebar.Pushable as={Segment}>
<Sidebar as={Menu} animation='overlay' direction='bottom' visible={visible} inverted>
<Menu.Item name='home'>
<Icon name='home' />
Home
</Menu.Item>
<Menu.Item name='gamepad'>
<Icon name='gamepad' />
Games
</Menu.Item>
<Menu.Item name='camera'>
<Icon name='camera' />
Channels
</Menu.Item>
</Sidebar>
<Sidebar.Pusher>
<Segment basic>
<Header as='h3'>Application Content</Header>
<Image src='/assets/images/wireframe/paragraph.png' />
</Segment>
</Sidebar.Pusher>
</Sidebar.Pushable>
</div>
)
}
}
class MyApp extends Component {
render () {
return(
<div>
<SidebarBottomOverlay.MyButton />
<SidebarBottomOverlay />
</div>
)
}
}
export default MyApp
最佳答案
我建议在呈现菜单和侧边栏组件的父组件中保留侧边栏的可见性状态。您的切换可见性方法也会移动到父组件。然后,您可以根据需要将可见性状态和切换功能作为 props 传递给每个子组件。
关于javascript - 如何返回不在 Sidebar 组件内打开侧边栏的 ReactJS 子级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47436809/
嗨,我最近使用 bootstrap 4 offcanvas 模板来构建我的网站 http://v4-alpha.getbootstrap.com/examples/offcanvas/# 现在我想让我
我有 2 个侧边栏 - 左侧和右侧。我希望左侧边栏始终可见,并编写此内容以在加载时打开它: $(document).on('pagebeforeshow', function(){ $("#l
我是一名优秀的程序员,十分优秀!