Skip to content

Commit 2feaac5

Browse files
committed
refactor(CDropdown): update close button behavior
1 parent 5e0f7f5 commit 2feaac5

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

packages/coreui-react/src/components/dropdown/CDropdownMenu.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import PropTypes from 'prop-types'
21
import React, { ElementType, FC, HTMLAttributes, useContext, useEffect, useRef } from 'react'
2+
import PropTypes from 'prop-types'
33
import classNames from 'classnames'
44
import { Popper, PopperChildrenProps } from 'react-popper'
55

@@ -59,12 +59,14 @@ export const CDropdownMenu: FC<CDropdownMenuProps> = ({
5959
}
6060
}, [visible])
6161

62-
const handleKeyup = (event: Event) => {
62+
const handleKeyup = (event: KeyboardEvent) => {
6363
if (autoClose === false) {
6464
return
6565
}
6666
if (!dropdownMenuRef.current?.contains(event.target as HTMLElement)) {
67-
setVisible(false)
67+
if (event.key === 'Escape') {
68+
setVisible(false)
69+
}
6870
}
6971
}
7072
const handleMouseUp = (event: Event) => {

0 commit comments

Comments
 (0)