-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Declaration for FormControlProps.onChange is incorrect #3583
Comments
I'm facing this problem as well. (I think.) With react-bootstrap 0.32.4, I would define the
If I try this with react-boostrap 1.0.0-beta.6, I get the following compiler error:
I can get rid of this error by modifying the type of function to be just:
but then I can't access any of the input element fields on export interface Props {
planet?: string;
}
interface State {
planet: string;
}
export class Hello extends React.Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = { planet: props.planet || "" }
}
public render() {
return (
<form>
<FormGroup>
<FormControl name="planet" type="text" value={this.state.planet}
onChange={this.handleChange} />
</FormGroup>
</form>
);
}
private handleChange = (event: React.FormEvent<FormControl>) => {
const state = {...this.state};
const name = event.currentTarget.name;
state[name] = event.currentTarget.value;
this.setState(state);
};
} results in the following compiler error: Interestingly, if instead of a FormControl, I use a Form.Check, then my code works as it did with react-bootstrap 0.32.4: export interface Props {
enabled?: boolean;
}
interface State {
enabled: boolean;
}
export class HelloCheck extends React.Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = { enabled: this.props.enabled || true };
}
public render() {
return (
<form>
<FormGroup>
<Form.Check type="checkbox"
name="enabled"
label="Enabled"
checked={this.state.enabled}
onChange={this.handleChange} />
</FormGroup>
</form>
);
}
private handleChange = (event: React.ChangeEvent<FormControl & HTMLInputElement>) => {
const state = {...this.state};
const name = event.currentTarget.name;
state[name] = event.currentTarget.checked;
this.setState(state);
};
} |
I'm also encountering this. Even lovelier would be if there were a simple type alias for |
…t-bootstrap#3583, react-bootstrap#3568, react-bootstrap#2781) - Added tests to simple.test.tsx
…react-bootstrap#3568,react-bootstrap#2781) - Added tests to simple.test.tsx
…react-bootstrap#3568,react-bootstrap#2781) - Added tests to simple.test.tsx
I also have this problem. For now, to avoid the error I cast the event type: onChange: (event:React.ChangeEvent<FormControl>) => {
const castEvent = event as unknown as React.ChangeEvent<HTMLInputElement>;
setValue(castEvent.target.value);
} |
@jquense can this be closed after the commit? |
The text was updated successfully, but these errors were encountered: