Skip to content

Latest commit

 

History

History
37 lines (24 loc) · 933 Bytes

no-blur.md

File metadata and controls

37 lines (24 loc) · 933 Bytes

Disallow usage of Element.prototype.blur() (github/no-blur)

💼 This rule is enabled in the 🔍 browser config.

Do not use element.blur(). Blurring an element causes the focus position to be reset causing accessibility issues when using keyboard or voice navigation. Instead, restore focus by calling element.focus() on a prior element.

Rule Details

👎 Examples of incorrect code for this rule:

menu.addEventListener('close', () => {
  input.blur()
})

👍 Examples of correct code for this rule:

menu.addEventListener('open', () => {
  const previouslyFocusedElement = document.activeElement

  input.focus()

  menu.addEventListener('close', () => {
    previouslyFocusedElement.focus()
  })
})

Version

4.3.2