Add InputHTMLAttributes to react-file-reader-input props (#45268)

This commit is contained in:
bjoluc 2020-06-10 16:55:24 +02:00 committed by GitHub
parent e6ef022554
commit ed3959641e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 8 deletions

View File

@ -1,8 +1,10 @@
// Type definitions for react-file-reader-input 1.1
// Type definitions for react-file-reader-input 2.0
// Project: https://github.com/ngokevin/react-file-reader-input
// Definitions by: Dmitry Rogozhny <https://github.com/dmitryrogozhny>, Ali Taheri <https://github.com/alitaheri>
// Definitions by: Dmitry Rogozhny <https://github.com/dmitryrogozhny>,
// Ali Taheri <https://github.com/alitaheri>,
// bjoluc <https://github.com/bjoluc>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
// TypeScript Version: 3.5
import * as React from 'react';
@ -13,7 +15,7 @@ declare namespace FileInput {
type Format = 'buffer' | 'binary' | 'url' | 'text';
type Result = [ProgressEvent, File];
interface Props {
interface Props extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'onChange'> {
/**
* what format the `FileReader` should read the file as
* (i.e., `'buffer'`, `'binary'`, `'url'`, `'text'`).
@ -23,7 +25,7 @@ declare namespace FileInput {
as?: Format;
/**
* Callback function called when the files are choosen by the user.
* Callback function called when the files are chosen by the user.
*
* Results will be an array of arrays, the size of which depending
* on how many files were selected.
@ -40,7 +42,7 @@ declare namespace FileInput {
* @param event The event that triggered file changes
* @param results The array of files
*/
onChange(event: React.SyntheticEvent<any>, results: Result[]): void;
onChange(event: React.ChangeEvent<HTMLInputElement>, results: Result[]): void;
}
}

View File

@ -1,5 +1,5 @@
import * as React from 'react';
import FileReaderInput = require('react-file-reader-input');
import FileReaderInput from 'react-file-reader-input';
class MyComponent extends React.Component {
handleChange = (event: React.SyntheticEvent<any>, results: FileReaderInput.Result[]) => {
@ -13,7 +13,7 @@ class MyComponent extends React.Component {
return (
<form>
<label htmlFor="my-file-input">Upload a File: </label>
<FileReaderInput as="binary" onChange={this.handleChange} >
<FileReaderInput as="binary" onChange={this.handleChange} accept=".txt">
<button>Select a file!</button>
</FileReaderInput>
</form>

View File

@ -5,6 +5,7 @@
"es6",
"dom"
],
"esModuleInterop": true,
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,