From 4e89f5c4ad5e7d11309ea318d6ca157ab092cb77 Mon Sep 17 00:00:00 2001 From: Michal Czaplinski Date: Thu, 25 May 2023 14:12:05 -0500 Subject: [PATCH 1/2] Move `No Behaviors` to be the first option --- packages/block-editor/src/hooks/behaviors.js | 31 ++++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/packages/block-editor/src/hooks/behaviors.js b/packages/block-editor/src/hooks/behaviors.js index 01cc20ff625b90..9a197c1e08b958 100644 --- a/packages/block-editor/src/hooks/behaviors.js +++ b/packages/block-editor/src/hooks/behaviors.js @@ -56,6 +56,23 @@ export const withBehaviors = createHigherOrderComponent( ( BlockEdit ) => { // Block behaviors take precedence over theme behaviors. const behaviors = merge( themeBehaviors, blockBehaviors || {} ); + const noBehaviorsOption = { + value: '', + label: __( 'No behaviors' ), + }; + + const behaviorsOptions = Object.entries( settings ) + .filter( ( [ , behaviorValue ] ) => behaviorValue ) // Filter out behaviors that are disabled. + .map( ( [ behaviorName ] ) => ( { + value: behaviorName, + label: + // Capitalize the first letter of the behavior name. + behaviorName[ 0 ].toUpperCase() + + behaviorName.slice( 1 ).toLowerCase(), + } ) ); + + const options = [ noBehaviorsOption, behaviorsOptions ]; + return ( <> @@ -65,19 +82,7 @@ export const withBehaviors = createHigherOrderComponent( ( BlockEdit ) => { label={ __( 'Behaviors' ) } // At the moment we are only supporting one behavior (Lightbox) value={ behaviors?.lightbox ? 'lightbox' : '' } - options={ Object.entries( settings ) - .filter( ( [ , behaviorValue ] ) => behaviorValue ) // Filter out behaviors that are disabled. - .map( ( [ behaviorName ] ) => ( { - value: behaviorName, - label: - // Capitalize the first letter of the behavior name. - behaviorName[ 0 ].toUpperCase() + - behaviorName.slice( 1 ).toLowerCase(), - } ) ) - .concat( { - value: '', - label: __( 'No behaviors' ), - } ) } + options={ options } onChange={ ( nextValue ) => { // If the user selects something, it means that they want to // change the default value (true) so we save it in the attributes. From 410a9668f288791e7ca204ae7675c719c12a7f15 Mon Sep 17 00:00:00 2001 From: Michal Czaplinski Date: Thu, 25 May 2023 14:24:15 -0500 Subject: [PATCH 2/2] Forgot the array spread --- packages/block-editor/src/hooks/behaviors.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-editor/src/hooks/behaviors.js b/packages/block-editor/src/hooks/behaviors.js index 9a197c1e08b958..7c2c0164640b29 100644 --- a/packages/block-editor/src/hooks/behaviors.js +++ b/packages/block-editor/src/hooks/behaviors.js @@ -71,7 +71,7 @@ export const withBehaviors = createHigherOrderComponent( ( BlockEdit ) => { behaviorName.slice( 1 ).toLowerCase(), } ) ); - const options = [ noBehaviorsOption, behaviorsOptions ]; + const options = [ noBehaviorsOption, ...behaviorsOptions ]; return ( <>