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
Extensibility: Define customClassname behavior as filtered blocks support #3472
Changes from 1 commit
e1e8138
6667db0
6d94b55
74b8cfa
3d54d33
73c3e30
5c38f6a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ import classnames from 'classnames'; | |
/** | ||
* WordPress dependencies | ||
*/ | ||
import { concatChildren } from '@wordpress/element'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
|
@@ -46,9 +45,9 @@ export function addAttribute( settings ) { | |
*/ | ||
export function addInspectorControl( element, props ) { | ||
if ( hasBlockSupport( props.name, 'customClassName', true ) && props.focus ) { | ||
element = concatChildren( | ||
element = [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tested it a bit, it works with |
||
element, | ||
<InspectorControls force> | ||
<InspectorControls key="inspector-custom-classname"> | ||
<InspectorControls.TextControl | ||
label={ __( 'Additional CSS Class' ) } | ||
value={ props.attributes.className || '' } | ||
|
@@ -58,8 +57,8 @@ export function addInspectorControl( element, props ) { | |
} ); | ||
} } | ||
/> | ||
</InspectorControls> | ||
); | ||
</InspectorControls>, | ||
]; | ||
} | ||
|
||
return element; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { pick, without, noop } from 'lodash'; | ||
import { pick, sortBy, forEach, without, noop } from 'lodash'; | ||
|
||
/** | ||
* WordPress dependencies | ||
|
@@ -61,6 +61,7 @@ class SlotFillProvider extends Component { | |
this.fills[ name ], | ||
instance | ||
); | ||
this.resetFillOccurrence( name ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is the most important line. It causes the key to update in |
||
this.forceUpdateSlot( name ); | ||
} | ||
|
||
|
@@ -69,15 +70,19 @@ class SlotFillProvider extends Component { | |
} | ||
|
||
getFills( name ) { | ||
return this.fills[ name ]; | ||
return sortBy( this.fills[ name ], 'occurrence' ); | ||
} | ||
|
||
resetFillOccurrence( name ) { | ||
forEach( this.fills[ name ], ( instance ) => { | ||
instance.resetOccurrence(); | ||
} ); | ||
} | ||
|
||
forceUpdateFills( name ) { | ||
if ( this.fills.hasOwnProperty( name ) ) { | ||
this.fills[ name ].forEach( ( instance ) => { | ||
instance.forceUpdate(); | ||
} ); | ||
} | ||
forEach( this.fills[ name ], ( instance ) => { | ||
instance.forceUpdate(); | ||
} ); | ||
} | ||
|
||
forceUpdateSlot( name ) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ class Filler extends Component { | |
render() { | ||
return [ | ||
<button key="1" type="button" onClick={ () => this.setState( { num: this.state.num + 1 } ) } />, | ||
<Fill name={ this.props.name } key="2">{ this.state.num.toString() }</Fill>, | ||
<Fill name={ this.props.name } key="2">{ this.props.text || this.state.num.toString() }</Fill>, | ||
]; | ||
} | ||
} | ||
|
@@ -96,4 +96,37 @@ describe( 'Slot', () => { | |
|
||
expect( element.find( 'Slot > div' ).html() ).toBe( '<div>2</div>' ); | ||
} ); | ||
|
||
it( 'should render in expected order', () => { | ||
const element = mount( | ||
<Provider> | ||
<Slot name="egg" key="slot" /> | ||
</Provider> | ||
); | ||
|
||
element.setProps( { | ||
children: [ | ||
<Slot name="egg" key="slot" />, | ||
<Filler name="egg" key="first" text="first" />, | ||
<Filler name="egg" key="second" text="second" />, | ||
], | ||
} ); | ||
|
||
element.setProps( { | ||
children: [ | ||
<Slot name="egg" key="slot" />, | ||
<Filler name="egg" key="second" text="second" />, | ||
], | ||
} ); | ||
|
||
element.setProps( { | ||
children: [ | ||
<Slot name="egg" key="slot" />, | ||
<Filler name="egg" key="first" text="first" />, | ||
<Filler name="egg" key="second" text="second" />, | ||
], | ||
} ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. element.setProps( {
children: [
<Slot name="egg" key="slot" />,
<Filler name="egg" key="second" text="second" />,
<Filler name="egg" key="first" text="first" />,
],
} ) I tried the following instead of line 122 and it outputs If I add the same code after line 128, it still renders |
||
|
||
expect( element.find( 'Slot > div' ).html() ).toBe( '<div>firstsecond</div>' ); | ||
} ); | ||
} ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed that because there is the opposite check above:
This check is obsolete. It will never be falsy here.