Skip to content

Commit f5c24b3

Browse files
wewoormumiao
authored andcommitted
fix(actionbar): merge onClick event
1 parent 7875f19 commit f5c24b3

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/components/actionBar/index.tsx

+9-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
getBEMElement,
66
getBEMModifier,
77
} from 'mo/common/className';
8+
import { mergeFunctions } from 'mo/common/utils';
89

910
export interface IActionBarItem<T = any> {
1011
id: string;
@@ -34,10 +35,8 @@ const labelClassName = getBEMElement(defaultActionBarClassName, 'label');
3435

3536
export function ActionBarItem(props: IActionBarItem) {
3637
const { id, title, name, onClick } = props;
37-
const click = (e: React.MouseEvent) => {
38-
if (onClick) {
39-
onClick(e, props);
40-
}
38+
const handClick = (e: React.MouseEvent) => {
39+
onClick?.(e, props);
4140
};
4241
const disabled = props.disabled ? itemDisabledClassName : null;
4342
const claNames = classNames(
@@ -49,7 +48,7 @@ export function ActionBarItem(props: IActionBarItem) {
4948
return (
5049
<li
5150
className={classNames(itemClassName, disabled)}
52-
onClick={click}
51+
onClick={handClick}
5352
key={`${id}`}
5453
>
5554
<a className={claNames} title={title}>
@@ -65,7 +64,11 @@ export default function ActionBar<T = any>(props: IActionBar<T>) {
6564
const claNames = classNames(defaultActionBarClassName, className);
6665

6766
const items = data.map((item: IActionBarItem<T>) => (
68-
<ActionBarItem key={item.id} onClick={onClick} {...item} />
67+
<ActionBarItem
68+
key={item.id}
69+
{...item}
70+
onClick={mergeFunctions(onClick, item.onClick)}
71+
/>
6972
));
7073

7174
return (

0 commit comments

Comments
 (0)