Skip to content

Commit 5f3fbe1

Browse files
makhmudjon-inadullaevMakhmudjon InadullaevMakhmudjon Inadullaev
authored
dropdown closes when esc key... (npm#254)
Co-authored-by: Makhmudjon Inadullaev <makhmudjon@Makhmudjons-MacBook-Pro-2.local> Co-authored-by: Makhmudjon Inadullaev <makhmudjon@MakhmudjonsMBP2.home>
1 parent a1265c8 commit 5f3fbe1

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

theme/src/components/variant-select.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,19 @@ function VariantSelect(props) {
5454
);
5555
});
5656

57+
/**
58+
* We should use '@primer/react' package as '@primer/components' package depricated and moved to '@primer/react'.
59+
* We have no closing/opening control with current '@primer/components' package, so document.body click event used for closing purpose.
60+
*/
61+
// TODO: We should use 'setOpen' function returned by the useDetails hook when we move to '@primer/react' package. https://primer.style/react/deprecated/Dropdown
62+
function onDropDownKeyDown (event) {
63+
if (event.key === 'Escape') {
64+
document.body.click()
65+
}
66+
}
67+
5768
return (
58-
<Dropdown overlay={props.overlay}>
69+
<Dropdown onKeyDown={onDropDownKeyDown} overlay={props.overlay}>
5970
<Dropdown.Button>{selectedItem.variant.title}</Dropdown.Button>
6071
<VariantSelect.Menu direction={props.direction} width={props.menuWidth}>
6172
{items}

0 commit comments

Comments
 (0)