Проблема при передаче React prop элементу DOM - PullRequest
0 голосов
/ 28 сентября 2018

Я пытаюсь ограничить ввод целыми числами.Я пытаюсь передать атрибут шага, который, кажется, работает, когда используется непосредственно в HTML, но мне трудно получить его от реакции.Ниже мой метод рендеринга, а числовой ввод внизу.Проблема, которую я имею, состоит в том, что ввод все еще принимает десятичное число.

render() {
    const {
      currentVariableValue,
      type,
      currentVariable,
      variablePayload,
    } = this.props

    const lowHi = this.getLowHi()
    const lowHiDisplay = `between ${lowHi[0]} and ${lowHi[1]}`
    /* eslint-disable no-nested-ternary */
    return (
      <ResponseContainer>
        {
          type === 'text' ?
            <TransparentTextArea
              autoFocus
              type="text"
              value={ currentVariableValue }
              onChange={ this.handleUpdateValue }
              onFocus={ this.handleFocus }
              onKeyPress={ this.handleKeyPress }
              key={ currentVariable }
            /> :
            type === 'paragraph' ?
              <TransparentTextArea
                autoFocus
                type="text"
                value={ currentVariableValue }
                onChange={ this.handleUpdateValue }
                onFocus={ this.handleFocus }
                onKeyPress={ this.handleKeyPress }
                key={ currentVariable }
                style={ { height: '300px', width: '95%', fontSize: '1.4em' } }
              /> :
              <TransparentInput
                autoFocus
                type="numeric"
                value={ currentVariableValue }
                onChange={ this.handleUpdateValue }
                onFocus={ this.handleFocus }
                onKeyPress={ this.handleKeyPress }
                key={ currentVariable }
                invalid={ !variablePayload.isValid }
                step={ 1 }
              />
        }

Ответы [ 2 ]

0 голосов
/ 28 сентября 2018

Ошибка в вашей type проп.Измените его на number.Нравится:

<TransparentInput
  autoFocus
  type="number"
0 голосов
/ 28 сентября 2018

В вашем TransparentInput вы передаете {... props} элементу ввода?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...