PR

devtoolsに`Blocked aria-hidden on an element…`と警告が表示される

記事内に広告が含まれています。
スポンサーリンク
Blocked aria-hidden on an element because its descendant retained focus. The focus must not be hidden from assistive technology users. Avoid using aria-hidden on a focused element or its ancestor. Consider using the inert attribute instead, which will also prevent focus. For more details, see the aria-hidden section of the WAI-ARIA specification at https://w3c.github.io/aria/#aria-hidden.

imasupの開発をしていたところ、上記のようなエラーがdevtoolsのコンソールに出力されていました。このエラー解消のための方法を紹介します。

このエラーってなに?

ざっくりいうと「モーダルを表示しているのに、後ろの要素にフォーカスが残ってるよ」というエラーです。

私の環境

  • vue3
  • tailwindcss
  • headlessUI

対応

imasupではモーダルにheadlessUIを使っており、呼び出すモーダルで初期フォーカス先を明示しました。

<script setup>
import { ref } from 'vue'
import { Dialog, DialogPanel } from '@headlessui/vue'

const isOpen = ref(true)
const completeButtonRef = ref(null)
</script>

<template>
  <Dialog :open="isOpen" @close="isOpen = false" :initialFocus="completeButtonRef">
    <DialogPanel>
      <button @click="isOpen = false">Cancel</button>
      <button ref="completeButtonRef" @click="isOpen = false">Complete</button>
    </DialogPanel>
  </Dialog>
</template>

参考

Bug Report: Intermittent console error when opening Dialog · Issue #3617 · tailwindlabs/headlessui
Description: An intermittent bug has been found in the Dialog component. After opening a modal window, an error occasion...

コメント

タイトルとURLをコピーしました