Autosuggest react.js组件不会在渲染时更新输入样式

时间:2016-02-04 06:00:19

标签: javascript css reactjs

我正在使用react-autosuggest component并且我使用反应内联样式设置其输入部分的边框样式,该内联样式根据用户输入而变化。但是,尽管每次调用render()时都会将新样式传递给Autosuggest组件,但它不会更新。这就是我所拥有的:

var borderStyle;
        if (gradient) {
            borderStyle = {
                borderImageSlice: 1,
                borderImage: '-webkit-linear-gradient(right, '+borderColour2+' 0%, '+borderColour2+' 40%, '+borderColour1+' 60%, '+borderColour1+' 100%) 1'
            };   
        }
        else {             
            borderStyle = {
                'borderColor': borderColour1
            };   
        }
        var theme = {
            container: 'react-autosuggest__container',
            containerOpen: 'react-autosuggest__container--open',
            input: borderStyle,
            suggestionsContainer: 'react-autosuggest__suggestions-container',
            suggestion: 'react-autosuggest__suggestion',
            suggestionFocused: 'react-autosuggest__suggestion--focused',
            sectionContainer: 'react-autosuggest__section-container',
            sectionTitle: 'react-autosuggest__section-title',
            sectionSuggestionsContainer: 'react-autosuggest__section-suggestions-container'
        };
<Autosuggest suggestions={suggestions}
    theme={theme}
    onSuggestionsUpdateRequested={this.onSuggestionsUpdateRequested}
    getSuggestionValue={getSuggestionValue}
    renderSuggestion={renderSuggestion}
    inputProps={inputProps}
    ref={this.saveInput}
    onSuggestionSelected={this.selectCard} />
除了输入,我使用默认值。我知道样式是有效的,因为我给它一个硬编码的渐变,并在第一页加载它显示它就像我想要的那样。我也知道'borderstyle'的值是正确的,并在传递到theme时更新,因此当theme传递到要渲染的组件时。

1 个答案:

答案 0 :(得分:0)

这应该在3.5.1版中修复。