From 68fda1fea8f0793a823827e4b921804613e47073 Mon Sep 17 00:00:00 2001 From: djhi Date: Tue, 13 Aug 2019 16:02:19 +0200 Subject: [PATCH] [RFR] Migrate TextInput to TypeScript --- .../{LongTextInput.spec.js => LongTextInput.spec.tsx} | 4 +++- .../src/input/{LongTextInput.js => LongTextInput.tsx} | 0 .../src/input/{TextInput.spec.js => TextInput.spec.tsx} | 4 +++- .../src/input/{TextInput.js => TextInput.tsx} | 9 ++++++--- 4 files changed, 12 insertions(+), 5 deletions(-) rename packages/ra-ui-materialui/src/input/{LongTextInput.spec.js => LongTextInput.spec.tsx} (96%) rename packages/ra-ui-materialui/src/input/{LongTextInput.js => LongTextInput.tsx} (100%) rename packages/ra-ui-materialui/src/input/{TextInput.spec.js => TextInput.spec.tsx} (96%) rename packages/ra-ui-materialui/src/input/{TextInput.js => TextInput.tsx} (87%) diff --git a/packages/ra-ui-materialui/src/input/LongTextInput.spec.js b/packages/ra-ui-materialui/src/input/LongTextInput.spec.tsx similarity index 96% rename from packages/ra-ui-materialui/src/input/LongTextInput.spec.js rename to packages/ra-ui-materialui/src/input/LongTextInput.spec.tsx index 4aa1bdc513f..2155b064e98 100644 --- a/packages/ra-ui-materialui/src/input/LongTextInput.spec.js +++ b/packages/ra-ui-materialui/src/input/LongTextInput.spec.tsx @@ -20,7 +20,9 @@ describe('', () => { render={() => } /> ); - const input = getByLabelText('resources.posts.fields.body'); + const input = getByLabelText( + 'resources.posts.fields.body' + ) as HTMLInputElement; expect(input.tagName).toEqual('TEXTAREA'); expect(input.value).toEqual('hello'); }); diff --git a/packages/ra-ui-materialui/src/input/LongTextInput.js b/packages/ra-ui-materialui/src/input/LongTextInput.tsx similarity index 100% rename from packages/ra-ui-materialui/src/input/LongTextInput.js rename to packages/ra-ui-materialui/src/input/LongTextInput.tsx diff --git a/packages/ra-ui-materialui/src/input/TextInput.spec.js b/packages/ra-ui-materialui/src/input/TextInput.spec.tsx similarity index 96% rename from packages/ra-ui-materialui/src/input/TextInput.spec.js rename to packages/ra-ui-materialui/src/input/TextInput.spec.tsx index 532dc5c0c64..50636a4dad8 100644 --- a/packages/ra-ui-materialui/src/input/TextInput.spec.js +++ b/packages/ra-ui-materialui/src/input/TextInput.spec.tsx @@ -21,7 +21,9 @@ describe('', () => { render={() => } /> ); - const TextFieldElement = getByLabelText('resources.posts.fields.title'); + const TextFieldElement = getByLabelText( + 'resources.posts.fields.title' + ) as HTMLInputElement; expect(TextFieldElement.value).toEqual('hello'); expect(TextFieldElement.getAttribute('type')).toEqual('text'); }); diff --git a/packages/ra-ui-materialui/src/input/TextInput.js b/packages/ra-ui-materialui/src/input/TextInput.tsx similarity index 87% rename from packages/ra-ui-materialui/src/input/TextInput.js rename to packages/ra-ui-materialui/src/input/TextInput.tsx index ff8f442d5d9..a78d474cb3e 100644 --- a/packages/ra-ui-materialui/src/input/TextInput.js +++ b/packages/ra-ui-materialui/src/input/TextInput.tsx @@ -1,6 +1,7 @@ -import React from 'react'; +import React, { FunctionComponent } from 'react'; import PropTypes from 'prop-types'; -import { useInput, FieldTitle } from 'ra-core'; +import { useInput, FieldTitle, InputProps } from 'ra-core'; +import { TextFieldProps } from '@material-ui/core/TextField'; import ResettableTextField from './ResettableTextField'; import InputHelperText from './InputHelperText'; @@ -20,7 +21,9 @@ import sanitizeRestProps from './sanitizeRestProps'; * * The object passed as `options` props is passed to the component */ -export const TextInput = ({ +export const TextInput: FunctionComponent< + InputProps & Omit +> = ({ label, options, resource,