-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
Copy pathDropdownMenu.jsx
65 lines (63 loc) · 1.59 KB
/
DropdownMenu.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import Menu, { Item as MenuItem } from '../../menu';
import PropTypes from '../../_util/vue-types';
import { OptionProps } from './Option';
import { inject } from 'vue';
function noop() {}
export default {
name: 'DropdownMenu',
props: {
prefixCls: PropTypes.string,
options: PropTypes.arrayOf(OptionProps),
},
setup() {
return {
mentionsContext: inject('mentionsContext'),
};
},
render() {
const {
notFoundContent,
activeIndex,
setActiveIndex,
selectOption,
onFocus = noop,
onBlur = noop,
} = this.mentionsContext;
const { prefixCls, options } = this.$props;
const activeOption = options[activeIndex] || {};
return (
<Menu
prefixCls={`${prefixCls}-menu`}
activeKey={activeOption.value}
onSelect={({ key }) => {
const option = options.find(({ value }) => value === key);
selectOption(option);
}}
onBlur={onBlur}
onFocus={onFocus}
>
{[
...options.map((option, index) => {
const { value, disabled, children } = option;
return (
<MenuItem
key={value}
disabled={disabled}
onMouseenter={() => {
setActiveIndex(index);
}}
>
{children}
</MenuItem>
);
}),
!options.length && (
<MenuItem key="notFoundContent" disabled>
{notFoundContent}
</MenuItem>
),
].filter(Boolean)}
</Menu>
);
},
};