【问题标题】:Autosuggest react.js component won't update input style on renderAutosuggest react.js 组件不会在渲染时更新输入样式
【发布时间】:2016-02-04 06:00:18
【问题描述】:

我正在使用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 传递到要渲染的组件时。

【问题讨论】:

    标签: javascript css reactjs


    【解决方案1】:

    这应该在版本 3.5.1 中得到修复。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-27
      • 2021-03-05
      • 2014-04-29
      • 2017-06-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多