import React from 'react'
import { Button } from 'semantic-ui-react'
const ButtonExampleShorthand = () => <Button content='Click Here' />
export default ButtonExampleShorthand
当你点击按钮时,它会变成灰色,并保持这样除非你点击其他地方。是否有可能使其在你点击后立即返回到初始状态(浅灰色)?
import React from 'react'
import { Button } from 'semantic-ui-react'
const ButtonExampleShorthand = () => <Button content='Click Here' />
export default ButtonExampleShorthand
当你点击按钮时,它会变成灰色,并保持这样除非你点击其他地方。是否有可能使其在你点击后立即返回到初始状态(浅灰色)?
这是 Button
的焦点状态,我建议你在按钮上保持焦点状态,但是你可以通过以下方式覆盖该样式。
在你的 CSS 文件中添加以下内容:
.ui.button:focus: {
background-color: #e0e1e2 none;
}
CustomButton
解决了这个问题。不知道这是否是最有效的解决方案。import { Button } from 'semantic-ui-react'
import { useRef } from 'react'
const CustomButton = ({children, ...props}) => {
const { onClick } = props
const buttonRef = useRef()
const handleOnClick = ({...props}) => {
buttonRef.current.ref.current.blur()
if (onClick) {
onClick(props)
}
}
return (
<Button {...props} ref={buttonRef} onClick={handleOnClick}>
{children}
</Button>
)
}
export default CustomButton