From 5c4caeb8c8a9b0b6117f3d70842eb47c5fd05ea1 Mon Sep 17 00:00:00 2001 From: Eugene Fedorenko Date: Mon, 21 Jan 2019 16:45:49 -0500 Subject: [PATCH 1/3] Added support for inputRef prop, which accepts a ref to be forwarded to the input --- types/react-mentions/index.d.ts | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/types/react-mentions/index.d.ts b/types/react-mentions/index.d.ts index ff10bbc013..f5892189b1 100644 --- a/types/react-mentions/index.d.ts +++ b/types/react-mentions/index.d.ts @@ -1,6 +1,7 @@ -// Type definitions for react-mentions 2.3 +// Type definitions for react-mentions 2.4 // Project: https://github.com/signavio/react-mentions // Definitions by: Scott Willeke +// Eugene Fedorenko // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 import * as React from "react"; @@ -41,21 +42,7 @@ export interface MentionsInputProps { style?: any; regex?: RegExp; suggestionsPortalHost?: Element; -} - -/** - * Exposes the type for use with the @see MentionsInputComponent.wrappedInstance which is added by react-mentions' use of substyle (https://github.com/jfschwarz/substyle). - */ -export interface MentionsInputComponentUnrwapped extends React.Component { - inputRef?: HTMLInputElement | HTMLTextAreaElement; -} - -/** - * Used with @see React.RefObject. - */ -export interface MentionsInputComponent extends React.Component { - // MentionsInput uses substyle (https://github.com/jfschwarz/substyle) which adds this wrappedInstance - wrappedInstance?: MentionsInputComponentUnrwapped; + inputRef?: React.RefObject | React.RefObject; } /** From 2b432174e931cf92adab8c66488dfc17e0605097 Mon Sep 17 00:00:00 2001 From: Eugene Fedorenko Date: Tue, 22 Jan 2019 12:53:19 -0500 Subject: [PATCH 2/3] Added inputRef to tests --- types/react-mentions/react-mentions-tests.tsx | 37 +++++++++++++------ types/react-mentions/tsconfig.json | 2 +- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/types/react-mentions/react-mentions-tests.tsx b/types/react-mentions/react-mentions-tests.tsx index 49f5180720..7611b29384 100644 --- a/types/react-mentions/react-mentions-tests.tsx +++ b/types/react-mentions/react-mentions-tests.tsx @@ -11,19 +11,32 @@ interface TestProps { } export const TestSimple: React.SFC = (props) => { + const inputEl = React.createRef(); + + function handleClick() { + if (inputEl.current) { + inputEl.current.focus(); + } + } + return ( - `@${login}`} - > - - + <> + `@${login}`} + inputRef={inputEl} + > + + + + + ); }; diff --git a/types/react-mentions/tsconfig.json b/types/react-mentions/tsconfig.json index 260c003e2d..973ede82b7 100644 --- a/types/react-mentions/tsconfig.json +++ b/types/react-mentions/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { "module": "commonjs", "lib": [ - "es6" + "es6", "dom" ], "noImplicitAny": true, "noImplicitThis": true, From 5e5ba551a34407f7175bef1c303ab60a9f6459c0 Mon Sep 17 00:00:00 2001 From: Eugene Fedorenko Date: Wed, 23 Jan 2019 12:47:43 -0500 Subject: [PATCH 3/3] Brought back MentionsInputComponent.wrappedInstance and MentionsInputComponentUnrwapped.inputRef --- types/react-mentions/index.d.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/types/react-mentions/index.d.ts b/types/react-mentions/index.d.ts index f5892189b1..ec9716aad7 100644 --- a/types/react-mentions/index.d.ts +++ b/types/react-mentions/index.d.ts @@ -45,6 +45,24 @@ export interface MentionsInputProps { inputRef?: React.RefObject | React.RefObject; } +/** + * Exposes the type for use with the @see MentionsInputComponent.wrappedInstance which is added by react-mentions' use of substyle (https://github.com/jfschwarz/substyle). + */ +export interface MentionsInputComponentUnrwapped extends React.Component { + /** + * @deprecated since version 2.4.0. Please use @see MentionsInputProps.inputRef + */ + inputRef?: HTMLInputElement | HTMLTextAreaElement; +} + +/** + * Used with @see React.RefObject. + */ +export interface MentionsInputComponent extends React.Component { + // MentionsInput uses substyle (https://github.com/jfschwarz/substyle) which adds this wrappedInstance + wrappedInstance?: MentionsInputComponentUnrwapped; +} + /** * Used to reference MentionsInput element in a TSX file. */