Skip to content

Commit

Permalink
feat(Item): forward event to onItemClick (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lunory authored Jul 25, 2023
1 parent ab35916 commit ac571dc
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/components/CompositeBar/Item/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ interface ItemPopup {
export interface ItemProps extends ItemPopup {
item: MenuItem;
enableTooltip?: boolean;
onItemClick?: (item: MenuItem, collapsed: boolean) => void;
onItemClick?: (
item: MenuItem,
collapsed: boolean,
event: React.MouseEvent<HTMLDivElement, MouseEvent>,
) => void;
}

interface ItemInnerProps extends ItemProps {
Expand Down Expand Up @@ -113,7 +117,7 @@ export const Item: React.FC<ItemInnerProps> = (props) => {
<div
className={b({type, current, compact}, className)}
ref={ref}
onClick={() => {
onClick={(event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
if (collapsedItem) {
/**
* If we call onItemClick for collapsedItem then:
Expand All @@ -122,7 +126,7 @@ export const Item: React.FC<ItemInnerProps> = (props) => {
*/
toggleOpen(!open);
} else {
onItemClick?.(item, false);
onItemClick?.(item, false, event);
}
}}
onMouseEnter={() => {
Expand Down Expand Up @@ -243,8 +247,10 @@ function CollapsedPopup({
const res = (
<div
className={b('collapse-item')}
onClick={() => {
onItemClick?.(collapseItem, true);
onClick={(
event: React.MouseEvent<HTMLDivElement, MouseEvent>,
) => {
onItemClick?.(collapseItem, true, event);
}}
>
{titleEl}
Expand Down

0 comments on commit ac571dc

Please sign in to comment.