feat: mentions (#2468)
parent
923e6231e4
commit
1dd43884d7
|
@ -1,4 +1,4 @@
|
||||||
import { inject, nextTick } from 'vue';
|
import { inject } from 'vue';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import omit from 'omit.js';
|
import omit from 'omit.js';
|
||||||
import PropTypes from '../_util/vue-types';
|
import PropTypes from '../_util/vue-types';
|
||||||
|
@ -7,7 +7,7 @@ import { mentionsProps } from '../vc-mentions/src/mentionsProps';
|
||||||
import Spin from '../spin';
|
import Spin from '../spin';
|
||||||
import BaseMixin from '../_util/BaseMixin';
|
import BaseMixin from '../_util/BaseMixin';
|
||||||
import { ConfigConsumerProps } from '../config-provider';
|
import { ConfigConsumerProps } from '../config-provider';
|
||||||
import { getOptionProps, getComponent, filterEmpty } from '../_util/props-util';
|
import { getOptionProps, getComponent, filterEmpty, getSlot } from '../_util/props-util';
|
||||||
|
|
||||||
const { Option } = VcMentions;
|
const { Option } = VcMentions;
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ const Mentions = {
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
nextTick(() => {
|
this.$nextTick(() => {
|
||||||
if (this.autoFocus) {
|
if (this.autoFocus) {
|
||||||
this.focus();
|
this.focus();
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@ const Mentions = {
|
||||||
},
|
},
|
||||||
getOptions() {
|
getOptions() {
|
||||||
const { loading } = this.$props;
|
const { loading } = this.$props;
|
||||||
const children = filterEmpty(this.$slots.default?.() || []);
|
const children = filterEmpty(getSlot(this) || []);
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return (
|
return (
|
||||||
|
@ -138,10 +138,11 @@ const Mentions = {
|
||||||
getPopupContainer,
|
getPopupContainer,
|
||||||
...restProps
|
...restProps
|
||||||
} = getOptionProps(this);
|
} = getOptionProps(this);
|
||||||
|
const { class: className, ...otherAttrs } = this.$attrs;
|
||||||
const prefixCls = getPrefixCls('mentions', customizePrefixCls);
|
const prefixCls = getPrefixCls('mentions', customizePrefixCls);
|
||||||
const otherProps = omit(restProps, ['loading']);
|
const otherProps = omit(restProps, ['loading']);
|
||||||
|
|
||||||
const mergedClassName = classNames({
|
const mergedClassName = classNames(className, {
|
||||||
[`${prefixCls}-disabled`]: disabled,
|
[`${prefixCls}-disabled`]: disabled,
|
||||||
[`${prefixCls}-focused`]: focused,
|
[`${prefixCls}-focused`]: focused,
|
||||||
});
|
});
|
||||||
|
@ -156,7 +157,7 @@ const Mentions = {
|
||||||
children: this.getOptions(),
|
children: this.getOptions(),
|
||||||
class: mergedClassName,
|
class: mergedClassName,
|
||||||
rows: 1,
|
rows: 1,
|
||||||
...this.$attrs,
|
...otherAttrs,
|
||||||
onChange: this.onChange,
|
onChange: this.onChange,
|
||||||
onSelect: this.onSelect,
|
onSelect: this.onSelect,
|
||||||
onFocus: this.onFocus,
|
onFocus: this.onFocus,
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { provide, nextTick } from 'vue';
|
import { provide } from 'vue';
|
||||||
|
import classNames from 'classnames';
|
||||||
import omit from 'omit.js';
|
import omit from 'omit.js';
|
||||||
import KeyCode from '../../_util/KeyCode';
|
import KeyCode from '../../_util/KeyCode';
|
||||||
import BaseMixin from '../../_util/BaseMixin';
|
import BaseMixin from '../../_util/BaseMixin';
|
||||||
|
@ -42,7 +43,7 @@ const Mentions = {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
updated() {
|
updated() {
|
||||||
nextTick(() => {
|
this.$nextTick(() => {
|
||||||
const { measuring } = this.$data;
|
const { measuring } = this.$data;
|
||||||
|
|
||||||
// Sync measure div top with textarea for rc-trigger usage
|
// Sync measure div top with textarea for rc-trigger usage
|
||||||
|
@ -173,7 +174,7 @@ const Mentions = {
|
||||||
this.setState({ isFocus: false });
|
this.setState({ isFocus: false });
|
||||||
this.stopMeasure();
|
this.stopMeasure();
|
||||||
this.$emit('blur', event);
|
this.$emit('blur', event);
|
||||||
}, 0);
|
}, 100);
|
||||||
},
|
},
|
||||||
selectOption(option) {
|
selectOption(option) {
|
||||||
const { _value: value, measureLocation, measurePrefix } = this.$data;
|
const { _value: value, measureLocation, measurePrefix } = this.$data;
|
||||||
|
@ -204,7 +205,7 @@ const Mentions = {
|
||||||
const { filterOption, children = [] } = this.$props;
|
const { filterOption, children = [] } = this.$props;
|
||||||
const list = (Array.isArray(children) ? children : [children])
|
const list = (Array.isArray(children) ? children : [children])
|
||||||
.map(item => {
|
.map(item => {
|
||||||
return { ...getOptionProps(item), children: item.children.default?.() || item.children };
|
return { ...getOptionProps(item), children: item.children.default?.() };
|
||||||
})
|
})
|
||||||
.filter(option => {
|
.filter(option => {
|
||||||
/** Return all result if `filterOption` is false. */
|
/** Return all result if `filterOption` is false. */
|
||||||
|
@ -254,6 +255,8 @@ const Mentions = {
|
||||||
...restProps
|
...restProps
|
||||||
} = getOptionProps(this);
|
} = getOptionProps(this);
|
||||||
|
|
||||||
|
const { class: className, style, ...otherAttrs } = this.$attrs;
|
||||||
|
|
||||||
const inputProps = omit(restProps, [
|
const inputProps = omit(restProps, [
|
||||||
'value',
|
'value',
|
||||||
'defaultValue',
|
'defaultValue',
|
||||||
|
@ -267,12 +270,12 @@ const Mentions = {
|
||||||
const options = measuring ? this.getOptions() : [];
|
const options = measuring ? this.getOptions() : [];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class={prefixCls}>
|
<div class={classNames(prefixCls, className)} style={style}>
|
||||||
<textarea
|
<textarea
|
||||||
ref="textarea"
|
ref="textarea"
|
||||||
{...{
|
{...{
|
||||||
...inputProps,
|
...inputProps,
|
||||||
...this.$attrs,
|
...otherAttrs,
|
||||||
onChange: noop,
|
onChange: noop,
|
||||||
onSelect: noop,
|
onSelect: noop,
|
||||||
}}
|
}}
|
||||||
|
|
Loading…
Reference in New Issue