Skip to content

Commit 5cb35f3

Browse files
Introduce Save and close on SelectPanel (#5956)
Co-authored-by: hectahertz <24622853+hectahertz@users.noreply.github.com> Co-authored-by: francinelucca <40550942+francinelucca@users.noreply.github.com>
1 parent 29ffc7f commit 5cb35f3

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

.changeset/small-dog-bark.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/react': patch
3+
---
4+
5+
Introduce Save and close on SelectPanel

packages/react/src/SelectPanel/SelectPanel.tsx

+11-9
Original file line numberDiff line numberDiff line change
@@ -501,35 +501,37 @@ function Panel({
501501
const showResponsiveCancelSaveButtons =
502502
variant !== 'modal' && usingFullScreenOnNarrow && isMultiSelectVariant(selected) && onCancel !== undefined
503503

504-
// The responsive save button is only covering a very specific case:
505-
// - anchored panel with multi select if there is no onCancel
506-
const showResponsiveSaveButton =
504+
// The responsive save and close button is only covering a very specific case:
505+
// - anchored panel with multi select if there is no onCancel.
506+
// This variant should disappear in the future, once onCancel is required,
507+
// but for now we need to support it so there is a user friendly way to close the panel.
508+
const showResponsiveSaveAndCloseButton =
507509
variant !== 'modal' && usingFullScreenOnNarrow && isMultiSelectVariant(selected) && onCancel === undefined
508510

509511
// If there is any element in the footer, we render it.
510512
const renderFooter =
511513
secondaryAction !== undefined ||
512514
showPermanentCancelSaveButtons ||
513-
showResponsiveSaveButton ||
515+
showResponsiveSaveAndCloseButton ||
514516
showResponsiveCancelSaveButtons
515517

516518
// If there's any permanent elements in the footer, we show it always.
517519
// The save button is only shown on small screens.
518520
const displayFooter =
519521
secondaryAction !== undefined || showPermanentCancelSaveButtons
520522
? 'always'
521-
: showResponsiveSaveButton || showResponsiveCancelSaveButtons
523+
: showResponsiveSaveAndCloseButton || showResponsiveCancelSaveButtons
522524
? 'only-small'
523525
: undefined
524526

525527
const stretchSecondaryAction =
526-
showResponsiveSaveButton || showResponsiveCancelSaveButtons
528+
showResponsiveSaveAndCloseButton || showResponsiveCancelSaveButtons
527529
? 'only-big'
528530
: showPermanentCancelSaveButtons
529531
? 'never'
530532
: 'always'
531533

532-
const stretchSaveButton = showResponsiveSaveButton && secondaryAction === undefined ? 'only-small' : 'never'
534+
const stretchSaveButton = showResponsiveSaveAndCloseButton && secondaryAction === undefined ? 'only-small' : 'never'
533535

534536
return (
535537
<>
@@ -671,7 +673,7 @@ function Panel({
671673
</Button>
672674
</div>
673675
) : null}
674-
{showResponsiveSaveButton ? (
676+
{showResponsiveSaveAndCloseButton ? (
675677
<div className={classes.ResponsiveSaveButton} data-stretch-save-button={stretchSaveButton}>
676678
<Button
677679
block
@@ -681,7 +683,7 @@ function Panel({
681683
onClose('click-outside')
682684
}}
683685
>
684-
Save
686+
Save and close
685687
</Button>
686688
</div>
687689
) : null}

0 commit comments

Comments
 (0)