给ActionIcon增加Ref转发以方便控制DOM。
This commit is contained in:
		| @@ -1,15 +1,16 @@ | |||||||
| import { Icon, IconProps } from '@iconify/react/dist/iconify.js'; | import { Icon, IconProps } from '@iconify/react/dist/iconify.js'; | ||||||
| import cx from 'clsx'; | import cx from 'clsx'; | ||||||
| import { MouseEvent, MouseEventHandler, useCallback } from 'react'; | import { MouseEvent, MouseEventHandler, RefObject, useCallback } from 'react'; | ||||||
| import styles from './ActionIcon.module.css'; | import styles from './ActionIcon.module.css'; | ||||||
|  |  | ||||||
| type ActionIconProps = { | type ActionIconProps = { | ||||||
|   icon: IconProps['icon']; |   icon: IconProps['icon']; | ||||||
|   onClick?: MouseEventHandler<HTMLButtonElement>; |   onClick?: MouseEventHandler<HTMLButtonElement>; | ||||||
|   extendClassName?: HTMLButtonElement['className']; |   extendClassName?: HTMLButtonElement['className']; | ||||||
|  |   ref: RefObject<HTMLButtonElement>; | ||||||
| }; | }; | ||||||
|  |  | ||||||
| export function ActionIcon({ icon, onClick, extendClassName }: ActionIconProps) { | export function ActionIcon({ icon, onClick, extendClassName, ref }: ActionIconProps) { | ||||||
|   const handleClick = useCallback( |   const handleClick = useCallback( | ||||||
|     (event: MouseEvent<HTMLButtonElement>) => { |     (event: MouseEvent<HTMLButtonElement>) => { | ||||||
|       onClick?.(event); |       onClick?.(event); | ||||||
| @@ -18,7 +19,11 @@ export function ActionIcon({ icon, onClick, extendClassName }: ActionIconProps) | |||||||
|   ); |   ); | ||||||
|  |  | ||||||
|   return ( |   return ( | ||||||
|     <button type="button" onClick={handleClick} className={cx(styles.action_icon, extendClassName)}> |     <button | ||||||
|  |       type="button" | ||||||
|  |       onClick={handleClick} | ||||||
|  |       className={cx(styles.action_icon, extendClassName)} | ||||||
|  |       ref={ref}> | ||||||
|       <Icon icon={icon} className={styles.icon} /> |       <Icon icon={icon} className={styles.icon} /> | ||||||
|     </button> |     </button> | ||||||
|   ); |   ); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user