Skip to content

Commit 81821db

Browse files
fix(SelectPanel): always show x button on single select (#5912)
1 parent f978534 commit 81821db

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

.changeset/light-snakes-deny.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/react": patch
3+
---
4+
5+
fix(SelectPanel): always show x button on single select

packages/react/src/SelectPanel/SelectPanel.features.stories.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ export const SingleSelect = () => {
191191
selected={selected}
192192
onSelectedChange={setSelected}
193193
onFilterChange={setFilter}
194-
onCancel={() => setOpen(false)}
195194
width="medium"
196195
message={selectedItemsSortedFirst.length === 0 ? NoResultsMessage(filter) : undefined}
197196
/>

packages/react/src/SelectPanel/SelectPanel.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,9 @@ export function SelectPanel({
431431
}
432432
}
433433

434+
// because of instant selection, canceling on single select is the same as closing the panel, no onCancel needed
435+
const shouldShowXButton = (onCancel || !isMultiSelectVariant(selected)) && usingFullScreenOnNarrow
436+
434437
return (
435438
<AnchoredOverlay
436439
renderAnchor={renderMenuAnchor}
@@ -468,19 +471,19 @@ export function SelectPanel({
468471
</div>
469472
) : null}
470473
</div>
471-
{onCancel && usingFullScreenOnNarrow && (
474+
{shouldShowXButton ? (
472475
<IconButton
473476
type="button"
474477
variant="invisible"
475478
icon={XIcon}
476479
aria-label="Cancel and close"
477480
className={classes.ResponsiveCloseButton}
478481
onClick={() => {
479-
onCancel()
482+
onCancel?.()
480483
onCancelRequested()
481484
}}
482485
/>
483-
)}
486+
) : null}
484487
</div>
485488
{notice && (
486489
<div aria-live="polite" data-variant={notice.variant} className={classes.Notice}>

0 commit comments

Comments
 (0)