Skip to content

Commit

Permalink
feat: add dropdownClassName (#91)
Browse files Browse the repository at this point in the history
* feat: add dropdownClassName

* chore: code clean
  • Loading branch information
MadCcc authored Mar 16, 2022
1 parent c1095a2 commit 70786e5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
1 change: 0 additions & 1 deletion examples/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class Demo extends React.Component {
defaultValue="Hello World"
onSelect={this.onSelect}
onFocus={this.onFocus}
onBlur={this.onBlur}
>
<Option value="light">Light</Option>
<Option value="bamboo">Bamboo</Option>
Expand Down
4 changes: 3 additions & 1 deletion src/KeywordTrigger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import DropdownMenu from './DropdownMenu';
import { OptionProps } from './Option';

import { Placement, Direction } from './Mentions';
import classNames from 'classnames';

const BUILT_IN_PLACEMENTS = {
bottomRight: {
Expand Down Expand Up @@ -50,10 +51,11 @@ interface KeywordTriggerProps {
transitionName?: string;
children?: React.ReactElement;
getPopupContainer?: () => HTMLElement;
dropdownClassName?: string;
}

class KeywordTrigger extends React.Component<KeywordTriggerProps, {}> {
public getDropdownPrefix = () => `${this.props.prefixCls}-dropdown`;
public getDropdownPrefix = () => classNames(`${this.props.prefixCls}-dropdown`, this.props.dropdownClassName);

public getDropdownElement = () => {
const { options } = this.props;
Expand Down
3 changes: 3 additions & 0 deletions src/Mentions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export interface MentionsProps extends BaseTextareaAttrs {
onFocus?: React.FocusEventHandler<HTMLTextAreaElement>;
onBlur?: React.FocusEventHandler<HTMLTextAreaElement>;
getPopupContainer?: () => HTMLElement;
dropdownClassName?: string;
}
interface MentionsState {
value: string;
Expand Down Expand Up @@ -363,6 +364,7 @@ class Mentions extends React.Component<MentionsProps, MentionsState> {
autoFocus,
notFoundContent,
getPopupContainer,
dropdownClassName,
...restProps
} = this.props;

Expand Down Expand Up @@ -416,6 +418,7 @@ class Mentions extends React.Component<MentionsProps, MentionsState> {
options={options}
visible
getPopupContainer={getPopupContainer}
dropdownClassName={dropdownClassName}
>
<span>{measurePrefix}</span>
</KeywordTrigger>
Expand Down
6 changes: 6 additions & 0 deletions tests/Mentions.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,10 @@ describe('Mentions', () => {
).toBe('Cat');
});
});

it('dropdownClassName should work', () => {
const wrapper = createMentions({ dropdownClassName: 'my-dropdown' });
simulateInput(wrapper, '@');
expect(wrapper.find('.my-dropdown').length).toBeTruthy();
});
});

0 comments on commit 70786e5

Please sign in to comment.