Vize

a11y/mouse-events-have-key-events

マウス操作と対応する focus / blur 操作を用意します。

既定の重大度 プリセット 自動修正 オプション
warning happy-path, nuxt, ecosystem, opinionated なし なし

適用範囲:Vue SFC のテンプレートと各ブロック。ルールに必要な script の文脈も例に含めています。

悪い例

プレビューの表示切り替えを mouseenter と mouseleave だけに指定しています。

<template>
  <div @mouseenter="showPreview" @mouseleave="hidePreview">Preview</div>
</template>

良い例

フォーカスできる button で、同じ操作を focus と blur からも実行します。

<template>
  <button
    type="button"
    @focus="showPreview"
    @blur="hidePreview"
    @mouseenter="showPreview"
    @mouseleave="hidePreview"
  >
    Preview
  </button>
</template>

設定(Vite+)

import { defineConfig } from "@vizejs/vite-plugin/vite-plus";

export default defineConfig({}).withVue({
  linter: {
    "preset": "incremental",
    "rules": {
      "a11y/mouse-events-have-key-events": "warn"
    }
  },
});

設定したら vp run lint を実行します。

関連ページ