Skip to content

Commit 2efeb82

Browse files
Move "No Behaviors" to be the first option in the list of behaviors. (#50979)
* Move `No Behaviors` to be the first option * Forgot the array spread
1 parent bc7030d commit 2efeb82

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

packages/block-editor/src/hooks/behaviors.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,23 @@ export const withBehaviors = createHigherOrderComponent( ( BlockEdit ) => {
5656
// Block behaviors take precedence over theme behaviors.
5757
const behaviors = merge( themeBehaviors, blockBehaviors || {} );
5858

59+
const noBehaviorsOption = {
60+
value: '',
61+
label: __( 'No behaviors' ),
62+
};
63+
64+
const behaviorsOptions = Object.entries( settings )
65+
.filter( ( [ , behaviorValue ] ) => behaviorValue ) // Filter out behaviors that are disabled.
66+
.map( ( [ behaviorName ] ) => ( {
67+
value: behaviorName,
68+
label:
69+
// Capitalize the first letter of the behavior name.
70+
behaviorName[ 0 ].toUpperCase() +
71+
behaviorName.slice( 1 ).toLowerCase(),
72+
} ) );
73+
74+
const options = [ noBehaviorsOption, ...behaviorsOptions ];
75+
5976
return (
6077
<>
6178
<BlockEdit { ...props } />
@@ -65,19 +82,7 @@ export const withBehaviors = createHigherOrderComponent( ( BlockEdit ) => {
6582
label={ __( 'Behaviors' ) }
6683
// At the moment we are only supporting one behavior (Lightbox)
6784
value={ behaviors?.lightbox ? 'lightbox' : '' }
68-
options={ Object.entries( settings )
69-
.filter( ( [ , behaviorValue ] ) => behaviorValue ) // Filter out behaviors that are disabled.
70-
.map( ( [ behaviorName ] ) => ( {
71-
value: behaviorName,
72-
label:
73-
// Capitalize the first letter of the behavior name.
74-
behaviorName[ 0 ].toUpperCase() +
75-
behaviorName.slice( 1 ).toLowerCase(),
76-
} ) )
77-
.concat( {
78-
value: '',
79-
label: __( 'No behaviors' ),
80-
} ) }
85+
options={ options }
8186
onChange={ ( nextValue ) => {
8287
// If the user selects something, it means that they want to
8388
// change the default value (true) so we save it in the attributes.

0 commit comments

Comments
 (0)