0

Есть input. При наборе вне инпута, инпут фокусируется и продолжается ввод. Добавлен события "document.addEventListener(keypress", ()=>ref.current.focus()). Нужно отменить ввод в input когда например открыто модальное окно. То есть когда открыта модалка, продолжается ввод.

1

1 ответ 1

0

const input = document.querySelector('input')
const modal = document.createElement('div')
modal.textContent = 'Надо вызвать .blur()'
Object.entries({
  fontSize: '36px',
  color: '#fff',
  backgroundColor: '#4caf50',
}).forEach(([s, v]) => modal.style[s] = v)

void async function() {
  let i = 10
  while (i--) {
    await new Promise((s) => setTimeout(s, 500))
    document.body.appendChild(modal)
    input.blur()
    input.value = 'blur()'
    await new Promise((s) => setTimeout(s, 500))
    document.body.removeChild(modal)
    input.focus()
    input.value = 'focus()'
  }
}()
<input type="text">
<br><br>

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.