Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block Editor: Remove 'React.Children' legacy API in 'Warning' component #67675

Merged
merged 2 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions packages/block-editor/src/components/warning/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import clsx from 'clsx';
/**
* WordPress dependencies
*/
import { Children } from '@wordpress/element';
import { DropdownMenu, MenuGroup, MenuItem } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { moreVertical } from '@wordpress/icons';
Expand All @@ -20,10 +19,10 @@ function Warning( { className, actions, children, secondaryActions } ) {
{ children }
</p>

{ ( Children.count( actions ) > 0 || secondaryActions ) && (
{ ( actions?.length > 0 || secondaryActions ) && (
<div className="block-editor-warning__actions">
{ Children.count( actions ) > 0 &&
Children.map( actions, ( action, i ) => (
{ actions?.length > 0 &&
actions.map( ( action, i ) => (
<span
key={ i }
className="block-editor-warning__action"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ describe( 'Warning', () => {

it( 'should show primary actions', () => {
render(
<Warning actions={ <button>Click me</button> }>Message</Warning>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why we allowed this behavior. The prop is used and documented as an array.

<Warning actions={ [ <button key="test">Click me</button> ] }>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an interesting case. Maybe we should account for the case where it's not an array.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked, and consumers have always treated actions as array props since the introduction - #5483.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't feel strongly :)

Message
</Warning>
);

expect(
Expand Down
Loading