Skip to content

Commit 1899fdf

Browse files
committed
fix: expose props to MenuItems even if not a direct child
1 parent a518b95 commit 1899fdf

5 files changed

Lines changed: 38 additions & 8 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ yarn-error.log*
1111
.cache
1212
dist
1313
*.log
14+
*.tgz
1415
cypress

README.session.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## To make a new release of this package
2+
3+
- Update the version in package.json,
4+
- Make your changes,
5+
- Make a PR and have it merged to main on https://github.com/session-foundation/session-react-contexify,
6+
- Once merged, draft a new release on https://github.com/session-foundation/session-react-contexify/releases,
7+
8+
Run those:
9+
10+
```sh
11+
yarn build && npm pack
12+
```
13+
14+
This should build a `.tgz` file, this is what you need to upload to the release on github.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "6.0.0",
2+
"version": "7.0.0",
33
"license": "MIT",
44
"main": "dist/index.js",
55
"module": "dist/index.mjs",

src/components/Item.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,13 @@ export const Item: React.FC<ItemProps> = ({
151151
e.stopPropagation();
152152

153153
if (!isDisabled) {
154-
!closeOnClick ? onClick(handlerParams) : dispatchUserHanlder();
154+
!closeOnClick ? onClick(handlerParams) : dispatchUserHandler();
155155
}
156156
}
157157

158158
// provide a feedback to the user that the item has been clicked before closing the menu
159-
function dispatchUserHanlder() {
159+
function dispatchUserHandler() {
160+
160161
const node = itemNode.current!;
161162
node.focus();
162163
node.addEventListener(
@@ -183,7 +184,7 @@ export const Item: React.FC<ItemProps> = ({
183184
e.stopPropagation();
184185
e.preventDefault();
185186
handlerParams.event = e;
186-
dispatchUserHanlder();
187+
dispatchUserHandler();
187188
}
188189
}),
189190
});
@@ -194,7 +195,7 @@ export const Item: React.FC<ItemProps> = ({
194195
if (e.key === 'Enter' || e.key === ' ') {
195196
e.stopPropagation();
196197
handlerParams.event = e;
197-
dispatchUserHanlder();
198+
dispatchUserHandler();
198199
}
199200
}
200201

src/components/utils.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { Children, cloneElement, ReactNode, ReactElement } from 'react';
1+
import {
2+
Children,
3+
cloneElement,
4+
Fragment,
5+
isValidElement,
6+
ReactNode,
7+
ReactElement,
8+
} from 'react';
29

310
import { BooleanPredicate, PredicateParams, TriggerEvent } from '../types';
411

@@ -13,11 +20,18 @@ export function isStr(v: any): v is String {
1320
export function cloneItems(
1421
children: ReactNode,
1522
props: { triggerEvent: TriggerEvent; propsFromTrigger?: object }
16-
) {
23+
): ReactNode {
1724
return Children.map(
1825
// remove null item
1926
Children.toArray(children).filter(Boolean),
20-
(item) => cloneElement(item as ReactElement<any>, props)
27+
(item) => {
28+
if (isValidElement(item) && item.type === Fragment) {
29+
return cloneElement(item as ReactElement<any>, {
30+
children: cloneItems((item.props as any).children, props),
31+
});
32+
}
33+
return cloneElement(item as ReactElement<any>, props);
34+
}
2135
);
2236
}
2337

0 commit comments

Comments
 (0)