Skip to content

Commit f76babc

Browse files
committed
fix textarea props not pass
1 parent 6bf9dde commit f76babc

File tree

4 files changed

+54
-5
lines changed

4 files changed

+54
-5
lines changed

examples/textarea.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* eslint no-console: 0 */
2+
3+
import React from 'react';
4+
import Mentions from '../src';
5+
import '../assets/index.less';
6+
7+
const { Option } = Mentions;
8+
9+
export default () => (
10+
<div>
11+
<Mentions placeholder="disabled" disabled>
12+
<Option value="light">Light</Option>
13+
<Option value="bamboo">Bamboo</Option>
14+
<Option value="cat">Cat</Option>
15+
</Mentions>
16+
17+
<Mentions placeholder="readonly" readOnly>
18+
<Option value="light">Light</Option>
19+
<Option value="bamboo">Bamboo</Option>
20+
<Option value="cat">Cat</Option>
21+
</Mentions>
22+
</div>
23+
);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rc-mentions",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"description": "React Mentions",
55
"keywords": [
66
"react",

src/Mentions.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,19 @@ import {
1010
filterOption as defaultFilterOption,
1111
getBeforeSelectionText,
1212
getLastMeasureIndex,
13+
omit,
14+
Omit,
1315
replaceWithMeasure,
1416
setInputSelection,
1517
validateSearch as defaultValidateSearch,
1618
} from './util';
1719

18-
export interface MentionsProps {
20+
type BaseTextareaAttrs = Omit<
21+
React.TextareaHTMLAttributes<HTMLTextAreaElement>,
22+
'prefix' | 'onChange' | 'onSelect'
23+
>;
24+
25+
export interface MentionsProps extends BaseTextareaAttrs {
1926
defaultValue?: string;
2027
value?: string;
2128
onChange?: (text: string) => void;
@@ -32,7 +39,6 @@ export interface MentionsProps {
3239
validateSearch?: typeof defaultValidateSearch;
3340
filterOption?: false | typeof defaultFilterOption;
3441
notFoundContent?: React.ReactNode;
35-
rows?: number;
3642
}
3743
interface MentionsState {
3844
value: string;
@@ -311,7 +317,9 @@ class Mentions extends React.Component<MentionsProps, MentionsState> {
311317

312318
public render() {
313319
const { value, measureLocation, measurePrefix, measuring, activeIndex } = this.state;
314-
const { prefixCls, className, style, autoFocus, notFoundContent, rows } = this.props;
320+
const { prefixCls, className, style, autoFocus, notFoundContent, ...restProps } = this.props;
321+
322+
const inputProps = omit(restProps, 'prefix', 'onSelect');
315323

316324
const options = measuring ? this.getOptions() : [];
317325

@@ -321,7 +329,7 @@ class Mentions extends React.Component<MentionsProps, MentionsState> {
321329
autoFocus={autoFocus}
322330
ref={this.setTextAreaRef}
323331
value={value}
324-
rows={rows}
332+
{...inputProps}
325333
onChange={this.onChange}
326334
onKeyDown={this.onKeyDown}
327335
onKeyUp={this.onKeyUp}

src/util.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
import { MentionsProps } from './Mentions';
22
import { OptionProps } from './Option';
33

4+
export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
5+
6+
type OmitFunc = <T extends object, K extends [...Array<keyof T>]>(
7+
obj: T,
8+
...keys: K
9+
) => { [K2 in Exclude<keyof T, K[number]>]: T[K2] };
10+
11+
export const omit: OmitFunc = (obj, ...keys) => {
12+
const clone = {
13+
...obj,
14+
};
15+
keys.forEach(key => {
16+
delete clone[key];
17+
});
18+
19+
return clone;
20+
};
21+
422
/**
523
* Cut input selection into 2 part and return text before selection start
624
*/

0 commit comments

Comments
 (0)