Skip to content

Commit 8e7bc0e

Browse files
fix(SelectPanel): differentiate onCancel gesture from escape (#5908)
1 parent 8fa12ea commit 8e7bc0e

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

.changeset/olive-kangaroos-wonder.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/react": patch
3+
---
4+
5+
fix(SelectPanel): differentiate onCancel gesture from escape

packages/react/src/SelectPanel/SelectPanel.tsx

+7-3
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ interface SelectPanelBaseProps {
7474
subtitle?: string | React.ReactElement
7575
onOpenChange: (
7676
open: boolean,
77-
gesture: 'anchor-click' | 'anchor-key-press' | 'click-outside' | 'escape' | 'selection',
77+
gesture: 'anchor-click' | 'anchor-key-press' | 'click-outside' | 'escape' | 'selection' | 'cancel',
7878
) => void
7979
placeholder?: string
8080
// TODO: Make `inputLabel` required in next major version
@@ -333,6 +333,10 @@ export function SelectPanel({
333333
[onOpenChange],
334334
)
335335

336+
const onCancelRequested = useCallback(() => {
337+
onOpenChange(false, 'cancel')
338+
}, [onOpenChange])
339+
336340
const renderMenuAnchor = useMemo(() => {
337341
if (renderAnchor === null) {
338342
return null
@@ -473,7 +477,7 @@ export function SelectPanel({
473477
className={classes.ResponsiveCloseButton}
474478
onClick={() => {
475479
onCancel()
476-
onClose('escape')
480+
onCancelRequested()
477481
}}
478482
/>
479483
)}
@@ -523,7 +527,7 @@ export function SelectPanel({
523527
size="medium"
524528
onClick={() => {
525529
onCancel()
526-
onClose('escape')
530+
onCancelRequested()
527531
}}
528532
>
529533
Cancel

0 commit comments

Comments
 (0)