Skip to content

Commit

Permalink
Fix external styles leaking into Warning component (#40868)
Browse files Browse the repository at this point in the history
* Add gutenberg-warning custom element

* Add only a wrapping div with all: initial

* Update jest snapshot

* Update the test case
  • Loading branch information
michalczaplinski authored May 10, 2022
1 parent ae18e3a commit 2732cf6
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 49 deletions.
89 changes: 47 additions & 42 deletions packages/block-editor/src/components/warning/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,50 +13,55 @@ import { moreHorizontal } from '@wordpress/icons';

function Warning( { className, actions, children, secondaryActions } ) {
return (
<div className={ classnames( className, 'block-editor-warning' ) }>
<div className="block-editor-warning__contents">
<p className="block-editor-warning__message">{ children }</p>
<div style={ { display: 'contents', all: 'initial' } }>
<div className={ classnames( className, 'block-editor-warning' ) }>
<div className="block-editor-warning__contents">
<p className="block-editor-warning__message">
{ children }
</p>

{ ( Children.count( actions ) > 0 || secondaryActions ) && (
<div className="block-editor-warning__actions">
{ Children.count( actions ) > 0 &&
Children.map( actions, ( action, i ) => (
<span
key={ i }
className="block-editor-warning__action"
{ ( Children.count( actions ) > 0 || secondaryActions ) && (
<div className="block-editor-warning__actions">
{ Children.count( actions ) > 0 &&
Children.map( actions, ( action, i ) => (
<span
key={ i }
className="block-editor-warning__action"
>
{ action }
</span>
) ) }
{ secondaryActions && (
<DropdownMenu
className="block-editor-warning__secondary"
icon={ moreHorizontal }
label={ __( 'More options' ) }
popoverProps={ {
position: 'bottom left',
className:
'block-editor-warning__dropdown',
} }
noIcons
>
{ action }
</span>
) ) }
{ secondaryActions && (
<DropdownMenu
className="block-editor-warning__secondary"
icon={ moreHorizontal }
label={ __( 'More options' ) }
popoverProps={ {
position: 'bottom left',
className: 'block-editor-warning__dropdown',
} }
noIcons
>
{ () => (
<MenuGroup>
{ secondaryActions.map(
( item, pos ) => (
<MenuItem
onClick={ item.onClick }
key={ pos }
>
{ item.title }
</MenuItem>
)
) }
</MenuGroup>
) }
</DropdownMenu>
) }
</div>
) }
{ () => (
<MenuGroup>
{ secondaryActions.map(
( item, pos ) => (
<MenuItem
onClick={ item.onClick }
key={ pos }
>
{ item.title }
</MenuItem>
)
) }
</MenuGroup>
) }
</DropdownMenu>
) }
</div>
) }
</div>
</div>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,25 @@

exports[`Warning should match snapshot 1`] = `
<div
className="block-editor-warning"
style={
Object {
"all": "initial",
"display": "contents",
}
}
>
<div
className="block-editor-warning__contents"
className="block-editor-warning"
>
<p
className="block-editor-warning__message"
<div
className="block-editor-warning__contents"
>
error
</p>
<p
className="block-editor-warning__message"
>
error
</p>
</div>
</div>
</div>
`;
2 changes: 1 addition & 1 deletion packages/block-editor/src/components/warning/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe( 'Warning', () => {
it( 'should have valid class', () => {
const wrapper = shallow( <Warning /> );

expect( wrapper.hasClass( 'block-editor-warning' ) ).toBe( true );
expect( wrapper.find( '.block-editor-warning' ) ).toHaveLength( 1 );
expect( wrapper.find( '.block-editor-warning__actions' ) ).toHaveLength(
0
);
Expand Down

0 comments on commit 2732cf6

Please sign in to comment.