diff --git a/components/form/style/index.less b/components/form/style/index.less
index fc6d3b7c8f..9a671ec4f4 100644
--- a/components/form/style/index.less
+++ b/components/form/style/index.less
@@ -390,6 +390,18 @@ form {
border-color: @error-color;
}
}
+ .ant-mention-wrapper,
+ .ant-mention-wrapper.active {
+ .ant-mention-editor {
+ border-color: @error-color;
+ box-shadow: 0 0 0 2px fade(@error-color, 20%);
+ &:not([disabled]):hover,
+ &:not([disabled]):focus {
+ border-color: @error-color;
+ box-shadow: 0 0 0 2px fade(@error-color, 20%);
+ }
+ }
+ }
}
.is-validating {
diff --git a/components/mention/demo/avatar.md b/components/mention/demo/avatar.md
index 63160d21fb..06195227e8 100644
--- a/components/mention/demo/avatar.md
+++ b/components/mention/demo/avatar.md
@@ -41,7 +41,7 @@ const CustomNavMention = React.createClass({
const suggestions = filtered.map(suggestion =>
);
diff --git a/components/mention/demo/basic.md b/components/mention/demo/basic.md
index 45237f2aaf..dbd0047e02 100644
--- a/components/mention/demo/basic.md
+++ b/components/mention/demo/basic.md
@@ -25,7 +25,7 @@ ReactDOM.render(
,
mountNode
);
diff --git a/components/mention/demo/controlled.md b/components/mention/demo/controlled.md
new file mode 100644
index 0000000000..1c98615408
--- /dev/null
+++ b/components/mention/demo/controlled.md
@@ -0,0 +1,86 @@
+---
+order: 3
+title: 受控模式
+---
+
+## zh-CN
+
+受控模式,例如配合 Form 使用
+
+## en-US
+
+Controlled mode, for example, work with `Form` .
+
+````jsx
+
+import { Mention, Form, Button } from 'antd';
+const { toEditorState, getMentions } = Mention;
+const FormItem = Form.Item;
+
+let App = React.createClass({
+ getInitialState() {
+ return {
+ initValue: toEditorState('@afc163'),
+ };
+ },
+ handleReset(e) {
+ e.preventDefault();
+ this.props.form.resetFields();
+ },
+ handleSubmit(e) {
+ e.preventDefault();
+ this.props.form.validateFields((errors, values) => {
+ if (!!errors) {
+ console.log('Errors in form!!!');
+ return;
+ }
+ console.log('Submit!!!');
+ console.log(values);
+ });
+ },
+ checkMention(rule, value, callback) {
+ const { getFieldValue } = this.props.form;
+ const mentions = getMentions(getFieldValue('mention'));
+ if (mentions.length < 2) {
+ callback(new Error('最帅的码农不止一个!!'));
+ } else {
+ callback();
+ }
+ },
+ render() {
+ const { getFieldProps, getFieldValue } = this.props.form;
+ const mentionProps = getFieldProps('mention', {
+ rules: [
+ { validator: this.checkMention },
+ ],
+ initialValue: this.state.initValue,
+ });
+ console.log('>> render', getFieldValue('mention') === this.state.initValue);
+ return (
);
+ },
+});
+
+
+App = Form.create()(App);
+ReactDOM.render(
+ ,
+ mountNode
+);
+````
diff --git a/components/mention/index.en-US.md b/components/mention/index.en-US.md
index e56e7644a9..c15d87bf49 100644
--- a/components/mention/index.en-US.md
+++ b/components/mention/index.en-US.md
@@ -21,6 +21,16 @@ When need to mention someone or something.
## API
+
+### Mention API
+
+| API | Description | Type |
+|----------|---------------|----------|--------------|
+| toString | convert EditorState to string | Function(editorState: EditorState): String |
+| toEditorState | convert string to EditorState | Function(string: String): EditorState |
+| getMentions | get mentioned people in current editorState | Function(editorState: EditorState): Array |
+
+
### Mention props
| Property | Description | Type | Default |
diff --git a/components/mention/index.tsx b/components/mention/index.tsx
index 9a84e9955f..1a995ef854 100644
--- a/components/mention/index.tsx
+++ b/components/mention/index.tsx
@@ -1,5 +1,5 @@
import * as React from 'react';
-import RcMention, { Nav, toString, toEditorState } from 'rc-editor-mention';
+import RcMention, { Nav, toString, toEditorState, getMentions } from 'rc-editor-mention';
import classnames from 'classnames';
export interface MentionProps {
@@ -25,6 +25,7 @@ export default class Mention extends React.Component
static Nav = Nav;
static toString = toString;
static toEditorState = toEditorState;
+ static getMentions = getMentions;
static defaultProps = {
prefixCls: 'ant-mention',
suggestions: [],
diff --git a/components/mention/index.zh-CN.md b/components/mention/index.zh-CN.md
index 240b27553f..3598a05874 100644
--- a/components/mention/index.zh-CN.md
+++ b/components/mention/index.zh-CN.md
@@ -21,6 +21,15 @@ english: Mention
## API
+### Mention API
+
+| API | 说明 | 类型 |
+|----------|---------------|----------|
+| toString | 把 EditorState 转成字符串 | Function(editorState: EditorState): String |
+| toEditorState | 把字符串转成 EditorState | Function(string: String): EditorState |
+| getMentions | 获取当前 editorState 中提到的人的列表 | Function(editorState: EditorState): Array |
+
+
### Mention props
| 参数 | 说明 | 类型 | 默认值 |
diff --git a/package.json b/package.json
index 2fb437a81d..8ad1cd9fe3 100644
--- a/package.json
+++ b/package.json
@@ -47,7 +47,7 @@
"rc-collapse": "~1.6.4",
"rc-dialog": "~6.2.1",
"rc-dropdown": "~1.4.8",
- "rc-editor-mention": "^0.1.0",
+ "rc-editor-mention": "^0.1.10",
"rc-form": "~0.17.1",
"rc-input-number": "~2.5.14",
"rc-menu": "~4.12.4",