a11y/mouse-events-have-key-events
マウス操作と対応する focus / blur 操作を用意します。
既定の重大度: warning
プリセット: happy-path, nuxt, ecosystem, opinionated
自動修正: なし。修正内容を確認してください
適用範囲: Vue SFC のテンプレート・ブロック。必要な script の文脈も例に含めています。
オプション: ルール固有のオプションはありません。重大度とプリセットは設定できます。
設定(Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({
lint: {
vize: {
"preset": "incremental",
"rules": {
"a11y/mouse-events-have-key-events": "warn"
}
},
},
});
vp run lint
悪い
プレビューの表示切り替えを 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>
良い例は上記の設定でこのルールの検出を避ける例です。他のルールでは検出される場合があります。