diff --git a/packages/core/src/components/button/ButtonGroup.tsx b/packages/core/src/components/button/ButtonGroup.tsx
index f778a00..7bc578f 100644
--- a/packages/core/src/components/button/ButtonGroup.tsx
+++ b/packages/core/src/components/button/ButtonGroup.tsx
@@ -21,8 +21,9 @@
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
+import { cloneChildren } from "@react-fabric/utilities";
import classNames from "classnames";
-import { Children, cloneElement } from "react";
+import { cloneElement } from "react";
import {
type AriaProps,
type ChildrenProp,
@@ -96,7 +97,7 @@ export const ButtonGroup = ({
)}
{...aria}
>
- {Children.map(children, (child: AnyObject) =>
+ {cloneChildren(children, (child: AnyObject) =>
cloneElement(child, {
color,
size,
diff --git a/packages/core/src/components/button/ToggleButtonGroup.tsx b/packages/core/src/components/button/ToggleButtonGroup.tsx
index 5e9944c..c96f0f6 100644
--- a/packages/core/src/components/button/ToggleButtonGroup.tsx
+++ b/packages/core/src/components/button/ToggleButtonGroup.tsx
@@ -21,9 +21,9 @@
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
-import { EMPTY_ARRAY, isArray } from "@react-fabric/utilities";
+import { cloneChildren, EMPTY_ARRAY, isArray } from "@react-fabric/utilities";
import classNames from "classnames";
-import { Children, cloneElement, useCallback, useMemo } from "react";
+import { cloneElement, useCallback, useMemo } from "react";
import { useControlledValue } from "../../hooks/useControlledValue";
import {
type AriaProps,
@@ -140,7 +140,7 @@ export const ToggleButtonGroup = ({
)}
{...aria}
>
- {Children.map(children, (child: AnyObject) =>
+ {cloneChildren(children, (child: AnyObject) =>
cloneElement(child, {
color,
size,
diff --git a/packages/core/src/components/menu/Menu.tsx b/packages/core/src/components/menu/Menu.tsx
index 4c05a56..64d4fd3 100644
--- a/packages/core/src/components/menu/Menu.tsx
+++ b/packages/core/src/components/menu/Menu.tsx
@@ -45,10 +45,9 @@ import {
useRole,
useTypeahead,
} from "@floating-ui/react";
-import { mergeRefs } from "@react-fabric/utilities";
+import { cloneChildren, mergeRefs } from "@react-fabric/utilities";
import classNames from "classnames";
import {
- Children,
cloneElement,
Fragment,
useCallback,
@@ -231,25 +230,23 @@ const MenuComponent = ({
// @ts-expect-error ignore
{...{ style: !isNested ? rest.style : floatingStyles }}
>
- {Children.map(children, (child: AnyObject, index) => {
- if (child) {
- labelsRef.current[index] = child.props.label;
- return cloneElement(
- child,
- nodeCheck(child, MenuItem, Menu, MenuComponent)
- ? {
- minimal: !isNested && minimal,
- "data-focus": activeIndex === index,
- ref: (el: HTMLElement) =>
- (elementsRef.current[index] = el),
- ...getItemProps({
- onClick: child.props.onClick,
- tabIndex: activeIndex === index ? 0 : -1,
- }),
- }
- : {},
- );
- }
+ {cloneChildren(children, (child: AnyObject, index) => {
+ labelsRef.current[index] = child.props.label;
+ return cloneElement(
+ child,
+ nodeCheck(child, MenuItem, Menu, MenuComponent)
+ ? {
+ minimal: !isNested && minimal,
+ "data-focus": activeIndex === index,
+ ref: (el: HTMLElement) =>
+ (elementsRef.current[index] = el),
+ ...getItemProps({
+ onClick: child.props.onClick,
+ tabIndex: activeIndex === index ? 0 : -1,
+ }),
+ }
+ : {},
+ );
})}
diff --git a/packages/core/stories/components/button/ButtonGroup.stories.tsx b/packages/core/stories/components/button/ButtonGroup.stories.tsx
index a8a0672..013b488 100644
--- a/packages/core/stories/components/button/ButtonGroup.stories.tsx
+++ b/packages/core/stories/components/button/ButtonGroup.stories.tsx
@@ -52,9 +52,12 @@ export const _ButtonGroup: ButtonGroupStory = {
return (