Browse Source

修正Action为A标签时且disabled, onClick事件还能点击

main
dark 2 weeks ago
parent
commit
403cc7e113
  1. 24
      src/components/action/Action.tsx

24
src/components/action/Action.tsx

@ -2,23 +2,27 @@ import { Button, ButtonProps } from 'antd'
import { useStyle } from './style' import { useStyle } from './style'
export interface ActionProps extends ButtonProps { export interface ActionProps extends ButtonProps {
as?: string
as?: string
} }
const Action = ({ title, as, children, ...props }: ActionProps) => { const Action = ({ title, as, children, ...props }: ActionProps) => {
const { styles } = useStyle()
const { styles } = useStyle()
const isLink = as === 'a' || props.type === 'link'
//fixme 如果外部同时设置 as={'a'} disabled={true} ,这里a标签会置灰,但是仍可点击,为什么不直接用Button?
const Comp = isLink ? 'a' : Button
return (
<span className={styles.container}>
const isLink = as === 'a' || props.type === 'link'
const Comp = isLink ? 'a' : Button
return (
<span className={styles.container}>
<Comp {...props} <Comp {...props}
type={isLink ? 'link' : props.type}
className={as === 'a' ? styles.actionA : ''}>{title ?? children}</Comp>
onClick={(e) => {
if (props.onClick && !props.disabled) {
props.onClick(e)
}
}}
type={isLink ? 'link' : props.type}
className={as === 'a' ? styles.actionA : ''}>{title ?? children}</Comp>
</span> </span>
)
)
} }
export default Action export default Action
Loading…
Cancel
Save