File tree 3 files changed +34
-0
lines changed
projects/plugins/jetpack/extensions/blocks/subscriptions
3 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -334,6 +334,9 @@ export default function SubscriptionControls( {
334
334
< fieldset >
335
335
< legend className = "wp-block-jetpack-subscriptions__legend" >
336
336
{ __ ( 'Categories' , 'jetpack' ) }
337
+ < small className = "wp-block-jetpack-subscriptions__help" >
338
+ { __ ( 'Select at least one category.' , 'jetpack' ) }
339
+ </ small >
337
340
</ legend >
338
341
{ availableNewsletterCategories . map ( category => (
339
342
< CheckboxControl
@@ -347,6 +350,11 @@ export default function SubscriptionControls( {
347
350
? excludedNewsletterCategoryIds . filter ( id => id !== category . id )
348
351
: [ ...excludedNewsletterCategoryIds , category . id ] ;
349
352
353
+ // One or more categories must be selected
354
+ if ( newExcludedIds . length === availableNewsletterCategories . length ) {
355
+ return ;
356
+ }
357
+
350
358
setAttributes ( {
351
359
excludedNewsletterCategoryIds : newExcludedIds ,
352
360
} ) ;
Original file line number Diff line number Diff line change 7
7
margin-bottom : 8px ;
8
8
padding : 0px ;
9
9
}
10
+
11
+ .wp-block-jetpack-subscriptions__help { // Meant to mimic .components-control__help
12
+ font-size : 12px ;
13
+ font-style : normal ;
14
+ font-weight : normal ;
15
+ color : rgb (117 , 117 , 117 );
16
+ line-height : 1.5 ;
17
+ display : block ;
18
+ text-transform : none ;
19
+ }
Original file line number Diff line number Diff line change @@ -350,6 +350,22 @@ describe( 'Inspector controls', () => {
350
350
excludedNewsletterCategoryIds : [ defaultProps . availableNewsletterCategories [ 0 ] . id ] ,
351
351
} ) ;
352
352
} ) ;
353
+
354
+ test ( 'enforces one category must be selected when enabled' , async ( ) => {
355
+ const user = userEvent . setup ( ) ;
356
+ render (
357
+ < SubscriptionsInspectorControls
358
+ { ...defaultProps }
359
+ autoSubscribeToNewsletterCategories
360
+ excludedNewsletterCategoryIds = { [ defaultProps . availableNewsletterCategories [ 1 ] . id ] }
361
+ />
362
+ ) ;
363
+
364
+ await user . click ( screen . getByText ( 'Settings' ) , { selector : 'button' } ) ;
365
+ await user . click ( screen . getByLabelText ( 'Category 1' ) ) ;
366
+
367
+ expect ( setAttributes ) . not . toHaveBeenCalled ( ) ;
368
+ } ) ;
353
369
} ) ;
354
370
} ) ;
355
371
} ) ;
You can’t perform that action at this time.
0 commit comments