Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 32 additions & 21 deletions src/DropdownMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import Menu, { MenuItem } from 'rc-menu';
import * as React from 'react';
import { MentionsContextConsumer, MentionsContextProps } from './MentionsContext';
import {
MentionsContextConsumer,
MentionsContextProps,
} from './MentionsContext';
import { OptionProps } from './Option';

interface DropdownMenuProps {
Expand Down Expand Up @@ -29,36 +32,44 @@ class DropdownMenu extends React.Component<DropdownMenuProps, {}> {
prefixCls={`${prefixCls}-menu`}
activeKey={activeOption.key}
onSelect={({ key }) => {
const option = options.find(({ key: optionKey }) => optionKey === key);
const option = options.find(
({ key: optionKey }) => optionKey === key,
);
selectOption(option);
}}
onFocus={onFocus}
onBlur={onBlur}
>
{options.map((option, index) => {
const { key, disabled, children, className, style } = option;
return (
<MenuItem
key={key}
disabled={disabled}
className={className}
style={style}
onMouseEnter={() => {
setActiveIndex(index);
}}
>
{children}
</MenuItem>
);
})}

{!options.length && <MenuItem disabled>{notFoundContent}</MenuItem>}
{options.length ? (
options.map((option, index) => {
const { key, disabled, children, className, style } = option;
return (
<MenuItem
key={`${key}_${index}`}
disabled={disabled}
className={className}
style={style}
onMouseEnter={() => {
setActiveIndex(index);
}}
>
{children}
</MenuItem>
);
})
) : (
<MenuItem key={notFoundContent || 'notfound'} disabled>
{notFoundContent || 'Not Found'}
</MenuItem>
)}
</Menu>
);
};

public render() {
return <MentionsContextConsumer>{this.renderDropdown}</MentionsContextConsumer>;
return (
<MentionsContextConsumer>{this.renderDropdown}</MentionsContextConsumer>
);
}
}

Expand Down