【发布时间】:2022-04-27 17:23:10
【问题描述】:
我正在关注如何创建抽屉滑出菜单的这个 Chakra 文档:https://chakra-ui.com/docs/overlay/drawer
使用以下组件:
import React from "react"
import ReactDom from "react-dom"
import {
Drawer,
DrawerBody,
DrawerFooter,
DrawerHeader,
DrawerOverlay,
DrawerContent,
DrawerCloseButton,
useDisclosure ,
Button,
Input,
IconButton
} from '@chakra-ui/react'
import styles from "./header.module.css"
import { HamburgerIcon } from '@chakra-ui/icons'
function DrawerExample() {
const { isOpen, onOpen, onClose } = useDisclosure()
const btnRef = React.useRef()
return (
<>
{/* <Button ref={btnRef} colorScheme='teal' onClick={onOpen}>
Open
</Button> */}
<IconButton ref={btnRef} aria-label='Open menu' icon={<HamburgerIcon />} onClick={onOpen}/>
<Drawer
isOpen={isOpen}
placement='left'
onClose={onClose}
finalFocusRef={btnRef}
>
<DrawerOverlay />
<DrawerContent>
<DrawerCloseButton className={styles.closeButton} />
<DrawerHeader>Create your account</DrawerHeader>
<DrawerBody>
<Input placeholder='Type here...' />
</DrawerBody>
<DrawerFooter>
<Button variant='outline' mr={3} onClick={onClose}>
Cancel
</Button>
<Button colorScheme='blue'>Save</Button>
</DrawerFooter>
</DrawerContent>
</Drawer>
</>
)
}
export default DrawerExample
我的 css 模块:
.drawer {
padding: 10px
}
.closeButton {
align-items:'left'
}
我可以创建滑出式菜单,但 <DrawerCloseButton /> 与滑出式抽屉的末端对齐。我想让关闭按钮在抽屉的开头对齐(这样它更靠近屏幕边缘。
我按照这篇文章将按钮左对齐,但它不起作用 React-Native Button Align Center 浏览器没有发生任何变化。
可能有人给我一些关于如何重新对齐滑出菜单上的关闭按钮图标的指导...
谢谢
【问题讨论】:
标签: css reactjs css-selectors chakra