From fc6507fe20a73089aa7074155de0de91c4e46878 Mon Sep 17 00:00:00 2001 From: "maksim.erekhinskii" Date: Mon, 16 Sep 2024 20:10:00 +0200 Subject: [PATCH] [publish] fix breadcrumbs work with React.Fragment containers as a transparent containers https://github.com/reactjs/rfcs/pull/61 --- package-lock.json | 34 +++++++++++++++++++++++++++++++++ package.json | 1 + src/breadcrumbs/breadcrumbs.tsx | 5 +++-- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4eb09d8d416..910da958c73 100644 --- a/package-lock.json +++ b/package-lock.json @@ -48,6 +48,7 @@ "postcss-loader": "^8.1.1", "postcss-modules-values-replace": "^4.2.0", "postcss-preset-env": "^10.0.3", + "react-keyed-flatten-children": "^3.0.2", "react-movable": "^3.3.1", "react-virtualized": "^9.22.5", "react-waypoint": "^10.3.0", @@ -27734,6 +27735,24 @@ "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz", "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==" }, + "node_modules/react-keyed-flatten-children": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/react-keyed-flatten-children/-/react-keyed-flatten-children-3.0.2.tgz", + "integrity": "sha512-5oiw2x9QlCSOTeAerw72e3ij0P+kJ60A7mtHvpabbOc4j3mvVQB3YpXCy2Qt/0YOuDWvAq3w/cGRuO7G20KISQ==", + "license": "MIT", + "dependencies": { + "react-is": "^18.2.0" + }, + "peerDependencies": { + "react": ">=15.0.0" + } + }, + "node_modules/react-keyed-flatten-children/node_modules/react-is": { + "version": "18.3.1", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-18.3.1.tgz", + "integrity": "sha512-/LLMVyas0ljjAtoYiPqYiL8VWXzUUdThrmU5+n20DZv+a+ClRoevUzw5JxU+Ieh5/c87ytoTBV9G1FiKfNJdmg==", + "license": "MIT" + }, "node_modules/react-lifecycles-compat": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz", @@ -53783,6 +53802,21 @@ "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz", "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==" }, + "react-keyed-flatten-children": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/react-keyed-flatten-children/-/react-keyed-flatten-children-3.0.2.tgz", + "integrity": "sha512-5oiw2x9QlCSOTeAerw72e3ij0P+kJ60A7mtHvpabbOc4j3mvVQB3YpXCy2Qt/0YOuDWvAq3w/cGRuO7G20KISQ==", + "requires": { + "react-is": "^18.2.0" + }, + "dependencies": { + "react-is": { + "version": "18.3.1", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-18.3.1.tgz", + "integrity": "sha512-/LLMVyas0ljjAtoYiPqYiL8VWXzUUdThrmU5+n20DZv+a+ClRoevUzw5JxU+Ieh5/c87ytoTBV9G1FiKfNJdmg==" + } + } + }, "react-lifecycles-compat": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz", diff --git a/package.json b/package.json index ec8e3d85076..31c4ead423b 100644 --- a/package.json +++ b/package.json @@ -232,6 +232,7 @@ "postcss-loader": "^8.1.1", "postcss-modules-values-replace": "^4.2.0", "postcss-preset-env": "^10.0.3", + "react-keyed-flatten-children": "^3.0.2", "react-movable": "^3.3.1", "react-virtualized": "^9.22.5", "react-waypoint": "^10.3.0", diff --git a/src/breadcrumbs/breadcrumbs.tsx b/src/breadcrumbs/breadcrumbs.tsx index 9760b6d651e..bee850be2af 100644 --- a/src/breadcrumbs/breadcrumbs.tsx +++ b/src/breadcrumbs/breadcrumbs.tsx @@ -1,5 +1,6 @@ import classNames from 'classnames'; -import {Children, Fragment, ReactNode} from 'react'; +import flattenChildren from 'react-keyed-flatten-children'; +import {Fragment, ReactNode} from 'react'; import styles from './breadcrumbs.css'; @@ -9,7 +10,7 @@ export interface BreadcrumbsSeparatorAttrs { } export default function Breadcrumbs({separatorClassName, children}: BreadcrumbsSeparatorAttrs) { - return Children.toArray(children).map((child, index) => ( + return flattenChildren(children).map((child, index) => ( // eslint-disable-next-line react/no-array-index-key {index > 0 && {'/'}}