简体   繁体   English

如何在元素上设置默认的focus()

[英]How do you set a default focus() on an element

I'm trying to make an Angular Application (uses D3.js) Web Accessible. 我正在尝试使Angular应用程序(使用D3.js)可访问Web。

Goal: When a user calls for a particular chart (in this case a sunburst), the chart expands into view. 目标:当用户要求特定的图表(在这种情况下为森伯斯特)时,该图表会扩展到视图中。 My intention is to create a default focus on a specific element of the chart so once the user calls/selects the chart, the chart will automatically have focus. 我的意图是在图表的特定元素上创建默认焦点,因此一旦用户调用/选择了图表,图表将自动具有焦点。

Problem: Once I expand the sunburst chart into view, the Tabbing order resets from the start of the page (there is no page load as its a Single Page Application). 问题:一旦我将森伯斯特图扩展到视图中,则制表顺序将从页面的开头重置(没有页面加载作为其单页面应用程序)。 Then the user would have to TAB through the whole page to navigate to the sunburst chart. 然后,用户将不得不在整个页面上进行制表以导航到朝阳图。 I have already set the center node to have an attribute of Tabindex:0 . 我已经将中心节点设置为具有Tabindex:0的属性。 So now the center node can be accessed via keyboard navigation (tabbing). 因此,现在可以通过键盘导航(制表符)访问中心节点。

var defaultNode = d3.select(sunburstChartdetail").select("path").attr("tabindex", 0);

I have tried: 我努力了:

  defaultNode.focus(); 

but I get a console error suggesting 'focus' is not a function 但出现控制台错误,提示“焦点”不是功能

NOTE: Unfortunately I cannot post the code for NDA reasons. 注意:不幸的是,由于NDA原因,我无法发布代码。

To focus on an element, you need to get a reference to the underlying DOM element: 为了专注于元素,您需要获取对底层DOM元素的引用:

d3.select("foobar").node().focus()

Or in your case: 或您的情况:

defaultNode.node().focus()

Documentation on selection.node() 有关selection.node()文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将焦点设置为HTML5 canvas元素? - How do you set focus to the HTML5 canvas element? 如何在角度元素中设置默认属性? - How do you set default attributes in an angular element? 如果另一个元素已经被聚焦,您如何聚焦body元素? - How do you focus the body element if another element is already focused? 你如何使$(this)选择器专注于当前元素? - How do you make the $(this) selector focus on current element? ENYOJS:将重点放在页面渲染的默认元素上 - ENYOJS: Set focus on default element on page render 当用户在该元素外单击时,您如何避免失去对 contenteditable 元素的关注? - How do you avoid losing focus on a contenteditable element when a user clicks outside that element? 如何将焦点设置在默认按钮组子元素上(页面加载后) - How to set focus on default button group child element (after page load) 在iPad上,如何通过Javascript事件在select元素上设置focus()而不显示选项? - On an iPad, how can you set focus() on a select element via Javascript event without showing options? 如何在没有所有HTML的情况下将焦点设置为HTML输入元素? - How can you set focus to an HTML input element without having all of the HTML? 如何为 Webdatarocks 默认导出设置文件名 - How do you set filename for Webdatarocks default export
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM