1
1
import Menu , { MenuItem } from 'rc-menu' ;
2
2
import * as React from 'react' ;
3
- import { MentionsContextConsumer , MentionsContextProps } from './MentionsContext' ;
4
- import { OptionProps } from './Option' ;
3
+ import MentionsContext from './MentionsContext' ;
4
+ import type { OptionProps } from './Option' ;
5
5
6
6
interface DropdownMenuProps {
7
7
prefixCls ?: string ;
@@ -12,54 +12,50 @@ interface DropdownMenuProps {
12
12
* We only use Menu to display the candidate.
13
13
* The focus is controlled by textarea to make accessibility easy.
14
14
*/
15
- class DropdownMenu extends React . Component < DropdownMenuProps , { } > {
16
- public renderDropdown = ( {
15
+ function DropdownMenu ( props : DropdownMenuProps ) {
16
+ const {
17
17
notFoundContent,
18
18
activeIndex,
19
19
setActiveIndex,
20
20
selectOption,
21
21
onFocus,
22
22
onBlur,
23
- } : MentionsContextProps ) => {
24
- const { prefixCls, options } = this . props ;
25
- const activeOption = options [ activeIndex ] || { } ;
23
+ } = React . useContext ( MentionsContext ) ;
26
24
27
- return (
28
- < Menu
29
- prefixCls = { `${ prefixCls } -menu` }
30
- activeKey = { activeOption . key }
31
- onSelect = { ( { key } ) => {
32
- const option = options . find ( ( { key : optionKey } ) => optionKey === key ) ;
33
- selectOption ( option ) ;
34
- } }
35
- onFocus = { onFocus }
36
- onBlur = { onBlur }
37
- >
38
- { options . map ( ( option , index ) => {
39
- const { key, disabled, children, className, style } = option ;
40
- return (
41
- < MenuItem
42
- key = { key }
43
- disabled = { disabled }
44
- className = { className }
45
- style = { style }
46
- onMouseEnter = { ( ) => {
47
- setActiveIndex ( index ) ;
48
- } }
49
- >
50
- { children }
51
- </ MenuItem >
52
- ) ;
53
- } ) }
25
+ const { prefixCls, options } = props ;
26
+ const activeOption = options [ activeIndex ] || { } ;
54
27
55
- { ! options . length && < MenuItem disabled > { notFoundContent } </ MenuItem > }
56
- </ Menu >
57
- ) ;
58
- } ;
28
+ return (
29
+ < Menu
30
+ prefixCls = { `${ prefixCls } -menu` }
31
+ activeKey = { activeOption . key }
32
+ onSelect = { ( { key } ) => {
33
+ const option = options . find ( ( { key : optionKey } ) => optionKey === key ) ;
34
+ selectOption ( option ) ;
35
+ } }
36
+ onFocus = { onFocus }
37
+ onBlur = { onBlur }
38
+ >
39
+ { options . map ( ( option , index ) => {
40
+ const { key, disabled, children, className, style } = option ;
41
+ return (
42
+ < MenuItem
43
+ key = { key }
44
+ disabled = { disabled }
45
+ className = { className }
46
+ style = { style }
47
+ onMouseEnter = { ( ) => {
48
+ setActiveIndex ( index ) ;
49
+ } }
50
+ >
51
+ { children }
52
+ </ MenuItem >
53
+ ) ;
54
+ } ) }
59
55
60
- public render ( ) {
61
- return < MentionsContextConsumer > { this . renderDropdown } </ MentionsContextConsumer > ;
62
- }
56
+ { ! options . length && < MenuItem disabled > { notFoundContent } </ MenuItem > }
57
+ </ Menu >
58
+ ) ;
63
59
}
64
60
65
61
export default DropdownMenu ;
0 commit comments