Skip to content

Commit

Permalink
feat(Item): add ref to itemWrapper options (#84)
Browse files Browse the repository at this point in the history
* feat(Item): add ref to itemWrapper options

* fix(CompositeBar/Item): set ref required prop
  • Loading branch information
Lunory authored Aug 17, 2023
1 parent 4646563 commit 1f3be59
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/components/CompositeBar/Item/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export const Item: React.FC<ItemInnerProps> = (props) => {
const params = {icon: iconNode, title: titleNode};
let node;

const opts = {compact, collapsed: false, item};
const opts = {compact, collapsed: false, item, ref};

if (typeof item.itemWrapper === 'function') {
node = item.itemWrapper(params, makeNode, opts) as React.ReactElement;
Expand All @@ -224,7 +224,7 @@ export const Item: React.FC<ItemInnerProps> = (props) => {
Item.displayName = 'Item';

interface CollapsedPopupProps {
anchorRef?: React.RefObject<HTMLElement>;
anchorRef: React.RefObject<HTMLElement>;
onClose: () => void;
}

Expand Down Expand Up @@ -273,7 +273,7 @@ function CollapsedPopup({

const titleNode = renderItemTitle(collapseItem);
const params = {title: titleNode};
const opts = {compact, collapsed: true, item: collapseItem};
const opts = {compact, collapsed: true, item: collapseItem, ref: anchorRef};
if (typeof collapseItem.itemWrapper === 'function') {
return collapseItem.itemWrapper(params, makeCollapseNode, opts);
} else {
Expand Down
7 changes: 6 additions & 1 deletion src/components/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ export interface MenuItem {
itemWrapper?: (
p: MakeItemParams,
makeItem: (p: MakeItemParams) => React.ReactNode,
opts: {collapsed: boolean; compact: boolean; item: MenuItem},
opts: {
collapsed: boolean;
compact: boolean;
item: MenuItem;
ref: React.RefObject<HTMLElement>;
},
) => React.ReactNode;
rightAdornment?: React.ReactNode;
type?: MenuItemType;
Expand Down

0 comments on commit 1f3be59

Please sign in to comment.