在使用elment中el-radio的时候发现控制台报错,

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.
Element with focus: input
Ancestor with aria-hidden:  <input type=​"radio" aria-hidden=​"true" tabindex=​"-1" autocomplete=​"off" class=​"el-radio__original" value=​"1">​

20250107145553.png

解决方案一:

::v-deep input[aria-hidden="true"] {
  display: none !important;
}

::v-deep .el-radio:focus:not(.is-focus):not(:active):not(.is-disabled) .el-radio__inner {
  box-shadow: none !important;
}

解决方案二:

自定义指令

  Vue.directive('removeAriaHidden', {
    bind(el, binding) {
      const ariaEls = el.querySelectorAll('.el-radio__original')
      ariaEls.forEach((item) => {
        item.removeAttribute('aria-hidden')
      })
    }
  })

页面使用

<el-radio-group v-model="tableRadio" class="new_radio" @change="changeRadio" v-removeAriaHidden></el-radio-group>

版权声明:本文为李维亮博主的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://www.liweiliang.com/1169.html

标签: none

评论已关闭