我在我的应用程序中实现了 react-datepicker。
一切都很好,除了我想自定义日期选择器的输入字段并使其适应我的其他自定义字段,如标题输入。
当我通过
customInput={<Input />}
字段,它的外观已经改变,但我不能再选择日期(选择器不再工作)。
继承人我的代码:
<DatePicker
customInput={<Input />}
dateFormat="DD.MM.YYYY"
selected=...
onChange=...
/>
有任何想法吗?
export namespace Input {
export interface Props {
onChange: (event: any) => void;
placeholder?: string;
value?: string | number;
isSecure?: any;
id?: string;
}
// ...
}
所以我通过以下方式添加了时钟事件:
export namespace Input {
export interface Props {
onChange: (event: any) => void;
placeholder?: string;
value?: string | number;
isSecure?: any;
id?: string;
onClick: (event: any) => void;
}
}
是对的吗?
组件代码:
export class Input extends React.Component<Input.Props, Input.State> {
public render() {
const controlClass = classNames(
[style.control]
);
const inputClass = classNames(
[style.input]
);
return (
<p className={controlClass} >
<input
id={this.props.id}
onChange={this.props.onChange}
className={inputClass}
type={this.props.isSecure ? "password" : "text"}
placeholder={this.props.placeholder}
value={this.props.value}
/>
</p>
);
}
}