首页 > 解决方案 > 在 BlueprintJs DateInput 上添加“small”属性或 .bp3-small

问题描述

我在我的应用程序中使用来自 BlueprintJS 的控件,并且输入框上有一个名为“small”的属性,它向其中添加了类“.bp3-small”以减小字体大小和组件高度。但是,这似乎在 DateInput 控件上不可用。我试过手动添加类:

<DateInput className="bp3-small"
                    showActionsBar={true}
                    small={true}
                    closeOnSelection={true}
                    value={props.data[props.fieldId]}
                    onChange={(newDate) => {
                        props.mutator(props.fieldId, newDate)
                    }}
                    popoverProps={{ position: Position.BOTTOM }}
                    formatDate={ date => date.toLocaleString()}
                    parseDate={str => new Date(str)}
                />

和:

<DateInput className=".bp3-small"
                    showActionsBar={true}
                    small={true}
                    closeOnSelection={true}
                    value={props.data[props.fieldId]}
                    onChange={(newDate) => {
                        props.mutator(props.fieldId, newDate)
                    }}
                    popoverProps={{ position: Position.BOTTOM }}
                    formatDate={ date => date.toLocaleString()}
                    parseDate={str => new Date(str)}
                />

但它仍然没有得到应用。我也尝试添加样式,但仍然没有运气。

<DateInput style={{fontSize: "12px", height:"24px"}}
                    showActionsBar={true}
                    small={true}
                    closeOnSelection={true}
                    value={props.data[props.fieldId]}
                    onChange={(newDate) => {
                        props.mutator(props.fieldId, newDate)
                    }}
                    popoverProps={{ position: Position.BOTTOM }}
                    formatDate={ date => date.toLocaleString()}
                    parseDate={str => new Date(str)}
                />

如何在所有BlueprintJS 组件中使用小样式?

我应该补充一点,我的 DateInput 在 FormGroup 内。我也尝试使用 FormGroup 的 contentClassName 属性但没有成功

谢谢,特洛伊

标签: javascriptreactjsblueprintjs

解决方案


啊,我找到了答案。有一个名为 inputProps 的参数将属性传递给底层输入,因此它可以工作:

inputProps={{small: true}}

推荐阅读