accessibility - Blazor FocusOnNavigate 设置 tabindex=-1

标签 accessibility blazor-server-side

我创建了一个 Blazor 项目,在 App.razor 中我有这一行:

<FocusOnNavigate RouteData="@routeData" Selector="input" />

FocusOnNavigate将焦点设置在导航后的第一个输入上。这工作正常,但我注意到使用选项卡您可以将焦点集中到下一个元素,但不可能将焦点重新集中在该元素上。这是因为输入现在有 tabindex="-1"

为什么要添加tabindex?有办法避免这种情况吗?

更新:我在不使用 FocusOnNavigate 的情况下尝试了输入的自动对焦属性,但这不起作用

最佳答案

mozilla他们说:

A negative value (usually tabindex="-1") means that the element is not reachable via sequential keyboard navigation, but could be focused with JavaScript or visually by clicking with the mouse. It's mostly useful to create accessible widgets with JavaScript.

Note: A negative value is useful when you have off-screen content that appears on a specific event. The user won't be able to focus any element with a negative tabindex using the keyboard, but a script can do so by calling the focus() method.

并辩称,我们可以通过在最后一个输入中使用onblure来解决这个问题,并再次将焦点集中在您的第一个输入上:

<EditFrom Model=model>

 //Input 1
 <InputText @ref="inputText1"
            class="form-control"
            bind-Value="model.val1"/>

 //Input 2
 <InputText
    class="form-control"
    bind-Value="model.val2"
    @onblure= OnblureHandler/>
</EditForm>

@code{
 puplic class Model
 {
    public string val1 {get; set;}
    public string val2 {get; set;}
 }
 Model model {get; set;}
 InputText inputText1;
 
 private void OnblureHandler()
 {
  if(inputText1.Element.HasValue) 
  {
    inputText1.Element.Value.FocusAsync();
  }
 }
}

关于accessibility - Blazor FocusOnNavigate 设置 tabindex=-1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72734337/

相关文章:

html - 具有特殊按键事件的元素的 ARIA 处理

blazor - blazor-server 组件中的 CSS 隔离

blazor - 在 'BlazorInputFile'中找不到 'window'

asp.net-core - Blazor 在上一个操作完成之前在此上下文中启动了第二个操作

winforms - 使自定义 WinForms 控件与讲述人一起使用(辅助功能)

css - 根据 WCAG 2.0,在 alt ="text"中使用的字符限制是多少?

html - 辅助功能问题 : Background Images Hiding Child Text

android - 对讲不读按钮名称

azure - 插槽交换时连接丢失

blazor-server-side - 如何启用 Blazor 热重载