范围输入定向道具-类型'DetailedHTMLProps <inputhtmlattributes <htmlinputelement>,HTMLInputElement>'不存在属性'orient'

时间:2018-11-10 12:17:09

标签: reactjs typescript jsx

试图创建一个带有“东方”属性的滑块输入。由于React输入的类型,我无法将其设置为“垂直”。

是否可以扩展声明以添加必要的道具?还是强制Typescript允许道具?

<input
    className={className("slider", props)}
    step={props.step}
    min={props.min}
    max={props.max}
    value={props.value}
    type="range"
    orient={props.isVertical ? "vertical" : "horizontal"}
    onChange={props.onChange}
/>

1 个答案:

答案 0 :(得分:0)

有一个解决方法。

<input
    ref="slider"
    className={className("slider", props)}
    step={props.step}
    min={props.min}
    max={props.max}
    value={props.value}
    type="range"
    orient={props.isVertical ? "vertical" : "horizontal"}
    onChange={props.onChange}
/>

然后在componentDidMount中执行以下操作

this.refs.slider.getDOMNode().orient = 'vertical';
相关问题