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

Move "No Behaviors" to be the first option in the list of behaviors. #50979

Merged
merged 2 commits into from
May 26, 2023
Merged
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
31 changes: 18 additions & 13 deletions packages/block-editor/src/hooks/behaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<>
<BlockEdit { ...props } />
Expand All @@ -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.
Expand Down